Hello,
I am new to access. I need to have the Default value in a field for a record as the SUM of all the values in another field where the value of a thirdr field is same. All fields have numeric values.
MC RefillTotal = sum of MC Refill for the same customer till the New record entry.
I try to put this as the default value for the MCRefTot field in the table , but not accepted as the synatax being not correct.
= Sum [MCRef] where [Cust_ID]=[Me]![Cust_ID]
Is this possible in Access with a correct synatx ?
I have searched for an example but couldn't find one. Can someone please help ?
34 2826
Sorry, I forgot to mention that I need this entry everytime I select a customer through a Combo Box.
So I would imagine that the Code will go in to AFterUpdate prperty of the Combo Box for selecting the customer.
Sorry, I forgot to mention that I need this entry everytime I select a customer through a Combo Box.
So I would imagine that the Code will go in to AFterUpdate prperty of the Combo Box for selecting the customer.
Hi. As far as I am aware this is not possible in any database. The default value is assigned when the table is designed. It is the value that will be assigned to this field by the database in the event that you create a new record and do not assign any value to the field.
I suspect, however, that you are thinking about something different from default values. Please explain something about your app and what you are trying to achieve with this database field
Thanks
Hi. As far as I am aware this is not possible in any database. The default value is assigned when the table is designed. It is the value that will be assigned to this field by the database in the event that you create a new record and do not assign any value to the field.
I suspect, however, that you are thinking about something different from default values. Please explain something about your app and what you are trying to achieve with this database field
Many thanks for the reply.
Perhaps I must clarify. Below is the main data entry form of my application. We disrtibute a product called MC Cloth to Shops to display. After a month we visit again and take stock of products sold, replenish and the shop pays for the products sold.
the Database keeps a record of the shop, products displayed, refilled, sold and respective payments.
The dtabase and the form is loaded in Handheld (PDAs) by the sales people who enter data during the visit and then synchronise with a master on return
Thanks
The entries I am trying to make are on the FORM and not on the table itself
I hope this explains
Many thanks again
You need to use the DSum function as you are not just referring to the current record.
= DSum("[MCRef]","Table/Query Name","[Cust_ID]=" & [Cust_ID])
You need to use the DSum function as you are not just referring to the current record.
= DSum("[MCRef]","Table/Query Name","[Cust_ID]=" & [Cust_ID])
Many thanks for the Help.
I have now this code as the Default Property fot the
MCRTot field
=DSum("[MCRef]","Miracle_Cloth_Main","[Name]=" & [Name])
However I notice that on selecting the Name of a supplier
from the combobox the FIRST record data for that supplier loads in the form and the Total doesnot apper
The code Inserted by the wizard while making the Combo is:
Private Sub Combo84_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.RecordsetClone
rs.FindFirst "[RecordNum] = " & Str(Nz(Me![Combo84], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
Is there a FindLast function? I can substitute for the FindFirst ?
Many thanks for the Help. I have now this code as the Default Property fot the MCRTot field
=DSum("[MCRef]","Miracle_Cloth_Main","[Name]=" & [Name])
If Name is a text field you will need to enclose in single quotes.
=DSum("[MCRef]","Miracle_Cloth_Main","[Name]='" & [Name] & "'")
However I notice that on selecting the Name of a supplierfrom the combobox the FIRST record data for that supplier loads in the form and the Total does not appear
The code Inserted by the wizard while making the Combo is: -
-
Private Sub Combo84_AfterUpdate()
-
' Find the record that matches the control.
-
Dim rs As Object
-
Set rs = Me.RecordsetClone
-
rs.FindFirst "[RecordNum] = " & Str(Nz(Me![Combo84], 0))
-
If Not rs.EOF Then
-
Me.Bookmark = rs.Bookmark
-
End Sub
-
Is there a FindLast function? I can substitute for the FindFirst ?
Just change rs.FindFirst to rs.FindLast
If Name is a text field you will need to enclose in single quotes.
=DSum("[MCRef]","Miracle_Cloth_Main","[Name]='" & [Name] & "'")
Just change rs.FindFirst to rs.FindLast
Many thanks for your help and replies.
I have corrected the code as it is a text field. Thanks.
I thought it is and changed to Rs.FindLast. However
it still doesn't show the total. On checking the table
I find that the Combo field entry doesn't get entered in the table though other data are getting saved when save button is pressed.
I guess some change is required in the After Update code below - Private Sub Combo84_AfterUpdate()
-
' Find the record that matches the control.
-
Dim rs As Object
-
-
Set rs = Me.RecordsetClone
-
rs.FindLast "[RecordNum] = " & Str(Nz(Me![Combo84], 0))
-
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
-
End Sub
-
-
Private Sub Combo84_NotInList(NewData As String, Response As Integer)
-
Dim Db As Database, rs As Recordset
-
Dim strmsg As String
-
strmsg = "'" & NewData & "' is not in Current List"
-
strmsg = strmsg & "@You Must Add it to Continue"
-
strmsg = strmsg & "@Click Yes to link or No to Cancel."
-
If MsgBox(strmsg, vbQuestion + vbYesNo, "Add new Description?") = vbNo Then
-
Response = acDataErrContinue
-
Else
-
Set Db = CurrentDb
-
Set rs = Db.OpenRecordset("Miracle_Cloth_Main", dbOpenDynaset)
-
On Error Resume Next
-
rs.AddNew
-
rs!Name = NewData
-
rs.Update
-
rs.Close
-
-
Set rs = Nothing
-
If Err Then
-
MsgBox "An error occurred. Please try again."
-
Response = acDataErrContinue
-
Else
-
Response = acDataErrAdded
-
End If
-
End If
-
-
End Sub
-
Private Sub Save_Record_Click()
-
On Error GoTo Err_Save_Record_Click
-
-
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
-
-
Exit_Save_Record_Click:
-
Exit Sub
-
-
Err_Save_Record_Click:
-
MsgBox Err.Description
-
Resume Exit_Save_Record_Click
-
-
End Sub
-
Private Sub NEWRECORD_Click()
-
On Error GoTo Err_NEWRECORD_Click
-
-
-
DoCmd.GoToRecord , , acNewRec
-
-
Exit_NEWRECORD_Click:
-
Exit Sub
-
-
Err_NEWRECORD_Click:
-
MsgBox Err.Description
-
Resume Exit_NEWRECORD_Click
-
-
End Sub
-
Private Sub Command88_Click()
-
On Error GoTo Err_Command88_Click
-
-
-
DoCmd.GoToRecord , , acNewRec
-
-
Exit_Command88_Click:
-
Exit Sub
-
-
Err_Command88_Click:
-
MsgBox Err.Description
-
Resume Exit_Command88_Click
-
-
End Sub
-
Private Sub Command89_Click()
-
On Error GoTo Err_Command89_Click
-
-
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
-
-
Exit_Command89_Click:
-
Exit Sub
-
-
Err_Command89_Click:
-
MsgBox Err.Description
-
Resume Exit_Command89_Click
-
-
End Sub
I thought it is and changed to Rs.FindLast. However
it still doesn't show the total. On checking the table
I find that the Combo field entry doesn't get entered in the table though other data are getting saved when save button is pressed.
The problem I think is that the control source property of your combo box is not bound to the appropriate field in the table.
In the properties of the combo box under the data tab change the control source to the field that you want the value stored in. It is probably blank at the moment.
The problem I think is that the control source property of your combo box is not bound to the appropriate field in the table.
In the properties of the combo box under the data tab change the control source to the field that you want the value stored in. It is probably blank at the moment.
Many thanks for the reply.
I guess the Cobo cannot be bound to a control dource for the selection or NotInList properties to work enabling entry of NEW data using the Combo.
I have now some code attached to the SAVe button which creates a NEW Record with the chosen Customer Name. However The FindLast still doesn't work as the
Name is not getting written from the Combo to the table
though other data is being saved.
Here is the New Code;
++++++++++++++++++ - Private Sub Name_Combo_AfterUpdate()
-
' Find the record that matches the control.
-
Dim rs As Object
-
-
Set rs = Me.Recordset.Clone
-
rs.FindLast "[RecordNum] = " & Str(Nz(Me![Name_Combo], 0))
-
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
-
End Sub
-
-
-
Private Sub Name_Combo_NotInList(NewData As String, Response As Integer)
-
-
Dim Db As Database, rs As Recordset
-
Dim strmsg As String
-
strmsg = "'" & NewData & "' is not in Current List"
-
strmsg = strmsg & "@You Must Add it to Continue"
-
strmsg = strmsg & "@Click Yes to link or No to Cancel."
-
If MsgBox(strmsg, vbQuestion + vbYesNo, "Add new Description?") = vbNo Then
-
Response = acDataErrContinue
-
Else
-
Set Db = CurrentDb
-
Set rs = Db.OpenRecordset("Miracle_Cloth_Main", dbOpenDynaset)
-
On Error Resume Next
-
rs.AddNew
-
rs!Name = NewData
-
rs.Update
-
rs.Close
-
-
Set rs = Nothing
-
If Err Then
-
MsgBox "An error occurred. Please try again."
-
Response = acDataErrContinue
-
Else
-
Response = acDataErrAdded
-
End If
-
End If
-
-
End Sub
-
-
Private Sub Save_Record_Click()
-
Dim Db As Database, rs As Recordset
-
Set Db = CurrentDb
-
Set rs = Db.OpenRecordset("Miracle_Cloth_Main", dbOpenDynaset)
-
-
rs.AddNew
-
rs.Close
-
-
-
On Error GoTo Err_Save_Record_Click
-
-
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
-
-
Exit_Save_Record_Click:
-
Exit Sub
-
-
Err_Save_Record_Click:
-
MsgBox Err.Description
-
Resume Exit_Save_Record_Click
-
-
End Sub
try
rs.FindPrevious
see if that will work
Many thanks for the reply.
I guess the Cobo cannot be bound to a control dource for the selection or NotInList properties to work enabling entry of NEW data using the Combo.
I have now some code attached to the SAVe button which creates a NEW Record with the chosen Customer Name. However The FindLast still doesn't work as the
Name is not getting written from the Combo to the table
though other data is being saved.
Here is the New Code;
++++++++++++++++++ - Private Sub Name_Combo_AfterUpdate()
-
' Find the record that matches the control.
-
Dim rs As Object
-
-
Set rs = Me.Recordset.Clone
-
rs.FindLast "[RecordNum] = " & Str(Nz(Me![Name_Combo], 0))
-
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
-
End Sub
-
-
-
Private Sub Name_Combo_NotInList(NewData As String, Response As Integer)
-
-
Dim Db As Database, rs As Recordset
-
Dim strmsg As String
-
strmsg = "'" & NewData & "' is not in Current List"
-
strmsg = strmsg & "@You Must Add it to Continue"
-
strmsg = strmsg & "@Click Yes to link or No to Cancel."
-
If MsgBox(strmsg, vbQuestion + vbYesNo, "Add new Description?") = vbNo Then
-
Response = acDataErrContinue
-
Else
-
Set Db = CurrentDb
-
Set rs = Db.OpenRecordset("Miracle_Cloth_Main", dbOpenDynaset)
-
On Error Resume Next
-
rs.AddNew
-
rs!Name = NewData
-
rs.Update
-
rs.Close
-
-
Set rs = Nothing
-
If Err Then
-
MsgBox "An error occurred. Please try again."
-
Response = acDataErrContinue
-
Else
-
Response = acDataErrAdded
-
End If
-
End If
-
-
End Sub
-
-
Private Sub Save_Record_Click()
-
Dim Db As Database, rs As Recordset
-
Set Db = CurrentDb
-
Set rs = Db.OpenRecordset("Miracle_Cloth_Main", dbOpenDynaset)
-
-
rs.AddNew
-
rs.Close
-
-
-
On Error GoTo Err_Save_Record_Click
-
-
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
-
-
Exit_Save_Record_Click:
-
Exit Sub
-
-
Err_Save_Record_Click:
-
MsgBox Err.Description
-
Resume Exit_Save_Record_Click
-
-
End Sub
try
rs.FindPrevious
see if that will work
Hello,
Many thanks again for the reply.
The problem is that any record saved based on the pulled down customer name gets saved with an empty customer name field. So there is only ONE record
which is called up by FindFIRST, LAST OR PREVIOUS.
The way to use the data is to call up the last saved record (From the last customer visit) change it with new
data and save it during the visit.
So what is required is some code to include the name field in the saved Record Set.
Hope you can help.
Hello,
Many thanks again for the reply.
The problem is that any record saved based on the pulled down customer name gets saved with an empty customer name field. So there is only ONE record
which is called up by FindFIRST, LAST OR PREVIOUS.
The way to use the data is to call up the last saved record (From the last customer visit) change it with new
data and save it during the visit.
So what is required is some code to include the name field in the saved Record Set.
Hope you can help.
I assume the problem is because the Name combobox is UNBOUND to the NAME field of the table.
Does anyone know how to save the Information
to UNBOUND field ?
Many thanks for any suggestions.
OK I've been rereading through the posts and I think I got the wrong impression somewhere about what you were trying to do. When you used Me.RecordsetClone and rs.FindFirst this was for searching a recordset to find a value or set of values and preform some action.
If all you want to do is to get the form to go to the record corresponding to the value selected in the combo box then you just need to use the following code: -
-
Private Sub Combo84_AfterUpdate()
-
-
Me.RecordNum.SetFocus
-
DoCmd.FindRecord Me.Combo84, acAnywhere, , acSearchAll, , acCurrent
-
-
End Sub
-
-
You may have to designate Me.Combo84 as a string. If so put:
DoCmd.FindRecord "'" & Me.Combo84 & "'", acAnywhere, , acSearchAll, , acCurrent
OK I've been rereading through the posts and I think I got the wrong impression somewhere about what you were trying to do. When you used Me.RecordsetClone and rs.FindFirst this was for searching a recordset to find a value or set of values and preform some action.
If all you want to do is to get the form to go to the record corresponding to the value selected in the combo box then you just need to use the following code: -
-
-
-
-
-
Private Sub Combo84_AfterUpdate()
-
-
Me.RecordNum.SetFocus
-
DoCmd.FindRecord Me.Combo84, acAnywhere, , acSearchAll, , acCurrent
-
-
End Sub
-
-
You may have to designate Me.Combo84 as a string. If so put:
DoCmd.FindRecord "'" & Me.Combo84 & "'", acAnywhere, , acSearchAll, , acCurrent
Many thanks.
Many thanks
All I am trying to achieve is the following
Name Cust_ID RecordNum Address
whs 0 1 ggggggggg
0 2 qqqqqqq
0 3 mmmmm
0 4 nnnnnnnnn
0 5 ooooooo
0 6 pppppp
When I select the Name from the Combo drop down
Iget the Record No1 with address gggggggggg as default
whereas what I need the record No 6 with address ppppp
(The last visit record which can be modified during the current visit)
My latest code is here : - Private Sub Name_Combo_AfterUpdate()
-
' This procedure tries to find the matching product's record.
-
' If the matching record is found, the procedure goes to it.
-
' If the record isn't found, the focus stays on the current record.
-
-
Dim Criteria As String ' This is the argument to the FindFirst method.
-
Dim MyRS As Recordset ' Recordset used to search.
-
Dim ComboName As String ' The name of the company to search for.
-
Const IDYES = 6
-
-
Set MyRS = Me.RecordsetClone
-
' Build the criteria.
-
ComboName = Chr$(34) & Screen.ActiveControl & Chr$(34)
-
Criteria = "[Name]=" & ComboName
-
' Perform the search.
-
-
MyRS.FindLast Criteria
-
If MyRS.NoMatch Then
-
-
Response = MsgBox("Could not find the Supplier Name: " & ComboName & " Do you wish to register a New Supplier: " & ComboName & " in this Database?", 4 + 48)
-
If Response = IDYES Then
-
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
Else
-
GoTo Endsub
-
End If
-
Else
-
'Synchronize the form's record to the dynaset's record.
-
Me.Bookmark = MyRS.Bookmark
-
-
End If
-
Endsub:
-
MyRS.Close
-
-
-
End Sub
This code seems to be entering the name in the COMBO
correctly. On doing trials I have found that getting the values entered in each record is not a good idea since it fills up the combo with the same customer name .
So to summarise the current issue:
I NEED the last record to load when a combo name is
pulled down and not the FIRST record.
I am sorry to be a bother but do realise that I am treading on the higher levels of ACCESS without a clue !
Is the Address a unique field? And is it a number or a string?
Can you post the exact SQL statement you are using for the 'row source' of the combo box. This will be either a table, saved query or a SELECT statement and can be found in the properties under the data tab.
Many thanks.
Many thanks
All I am trying to achieve is the following
Name Cust_ID RecordNum Address
whs 0 1 ggggggggg
0 2 qqqqqqq
0 3 mmmmm
0 4 nnnnnnnnn
0 5 ooooooo
0 6 pppppp
When I select the Name from the Combo drop down
Iget the Record No1 with address gggggggggg as default
whereas what I need the record No 6 with address ppppp
(The last visit record which can be modified during the current visit)
My latest code is here : - Private Sub Name_Combo_AfterUpdate()
-
' This procedure tries to find the matching product's record.
-
' If the matching record is found, the procedure goes to it.
-
' If the record isn't found, the focus stays on the current record.
-
-
Dim Criteria As String ' This is the argument to the FindFirst method.
-
Dim MyRS As Recordset ' Recordset used to search.
-
Dim ComboName As String ' The name of the company to search for.
-
Const IDYES = 6
-
-
Set MyRS = Me.RecordsetClone
-
' Build the criteria.
-
ComboName = Chr$(34) & Screen.ActiveControl & Chr$(34)
-
Criteria = "[Name]=" & ComboName
-
' Perform the search.
-
-
MyRS.FindLast Criteria
-
If MyRS.NoMatch Then
-
-
Response = MsgBox("Could not find the Supplier Name: " & ComboName & " Do you wish to register a New Supplier: " & ComboName & " in this Database?", 4 + 48)
-
If Response = IDYES Then
-
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
Else
-
GoTo Endsub
-
End If
-
Else
-
'Synchronize the form's record to the dynaset's record.
-
Me.Bookmark = MyRS.Bookmark
-
-
End If
-
Endsub:
-
MyRS.Close
-
-
-
End Sub
This code seems to be entering the name in the COMBO
correctly. On doing trials I have found that getting the values entered in each record is not a good idea since it fills up the combo with the same customer name .
So to summarise the current issue:
I NEED the last record to load when a combo name is
pulled down and not the FIRST record.
I am sorry to be a bother but do realise that I am treading on the higher levels of ACCESS without a clue !
Is the Address a unique field? And is it a number or a string?
Can you post the exact SQL statement you are using for the 'row source' of the combo box. This will be either a table, saved query or a SELECT statement and can be found in the properties under the data tab.
Adress is not a unique field. RecordNumber has been set as an Auto Number and Primary Key and the only unique field. I showed address only as an example to
show the First/last issue.
Here is the ROW source property of the Combo
SELECT [Name] FROM Miracle_Cloth_Main;
OK try this instead: -
-
Private Sub Name_Combo_AfterUpdate() -
' This procedure tries to find the matching product's record.
-
' If the matching record is found, the procedure goes to it.
-
' If the record isn't found, the focus stays on the current record.
-
Dim recNo As Long
-
-
' for this to work there cannot be any RecordNumber with a value of 0
-
' it finds the highest record number for the name in the combo box
-
' and returns 0 and exits if no record found.
-
recNo = nz(DMax("[RecordNumber]", "Query or Table behind form","[Name]='" & Me.Name_Combo & "'"), 0)
-
If recNo = 0 Then
-
Exit Sub
-
End If
-
Me.RecordNumber.SetFocus
-
DoCmd.FindRecord "'" & recNo & "'", acAnywhere, , acSearchAll, , acCurrent
-
-
End Sub
-
-
OK try this instead: -
-
Private Sub Name_Combo_AfterUpdate() -
' This procedure tries to find the matching product's record.
-
' If the matching record is found, the procedure goes to it.
-
' If the record isn't found, the focus stays on the current record.
-
Dim recNo As Long
-
-
' for this to work there cannot be any RecordNumber with a value of 0
-
' it finds the highest record number for the name in the combo box
-
' and returns 0 and exits if no record found.
-
recNo = nz(DMax("[RecordNumber]", "Query or Table behind form","[Name]='" & Me.Name_Combo & "'"), 0)
-
If recNo = 0 Then
-
Exit Sub
-
End If
-
Me.RecordNumber.SetFocus
-
DoCmd.FindRecord "'" & recNo & "'", acAnywhere, , acSearchAll, , acCurrent
-
-
End Sub
-
-
I have tried appending the code below . No change in results but No error messages -
Dim recNo As Long
-
-
' for this to work there cannot be any RecordNumber with a value of 0
-
' it finds the highest record number for the name in the combo box
-
' and returns 0 and exits if no record found.
-
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Name]='" & Me.Name_Combo & "'"), 0)
-
If recNo = 0 Then
-
Exit Sub
-
End If
-
Me.Text90.SetFocus
-
DoCmd.FindRecord "'" & recNo & "'", acAnywhere, , acSearchAll, , acCurrent
Add the line in bold and tell me exactly what appears on the screen. Is it what you expect?
Dim recNo As Long
' for this to work there cannot be any RecordNumber with a value of 0
' it finds the highest record number for the name in the combo box
' and returns 0 and exits if no record found.
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Name]='" & Me.Name_Combo & "'"), 0) Debug.Print "RecordNo: " & recNo & " and Name: '" & Me.Name_Combo & "'"
If recNo = 0 Then
Exit Sub
End If
Me.Text90.SetFocus
DoCmd.FindRecord "'" & recNo & "'", acAnywhere, , acSearchAll, , acCurrent
NeoPa 32,556
Expert Mod 16PB
NB.
Before you try this make sure you've type Ctrl-G to open the Debug window.
What Mary's after should appear in there - be ready to Copy and Paste it back in here as a post.
Good luck.
NB.
Before you try this make sure you've type Ctrl-G to open the Debug window.
What Mary's after should appear in there - be ready to Copy and Paste it back in here as a post.
Good luck.
If you can't figure out how to do that you can use a message box instead: Msgbox "RecordNo: " & recNo & " and Name: '" & Me.Name_Combo & "'"
If you can't figure out how to do that you can use a message box instead: Msgbox "RecordNo: " & recNo & " and Name: '" & Me.Name_Combo & "'"
Many thanks for the help again
Here is what I get in the DEBUG window
RecordNo: 1 and Name: 'whs'
RecordNo: 8 and Name: 'Kickstart'
+++++++++++++++++
Below is actual TABLE
Name Cust_ID RecordNum Address
whs 0 1 ggggggggg
0 2 qqqqqqq
0 3 mmmmm
0 4 nnnnnnnnn
0 5 ooooooo
0 6 pppppp
Kickstart 0 8 xyz
0 9 898989898
0 12 mmp
0 13 qty
Many thanks for the help again
Here is what I get in the DEBUG window
RecordNo: 1 and Name: 'whs'
RecordNo: 8 and Name: 'Kickstart'
+++++++++++++++++
Below is actual TABLE
Name Cust_ID RecordNum Address
whs 0 1 ggggggggg
0 2 qqqqqqq
0 3 mmmmm
0 4 nnnnnnnnn
0 5 ooooooo
0 6 pppppp
Kickstart 0 8 xyz
0 9 898989898
0 12 mmp
0 13 qty
I think your problem is that you've only entered the [Name] once. Therefore there is no way to relate the other records to the [Name].
Copy the [Name] value down as below and you should find my last code will work. -
-
Name Cust_ID RecordNum Address
-
whs 0 1 ggggggggg
-
whs 0 2 qqqqqqq
-
whs 0 3 mmmmm
-
whs 0 4 nnnnnnnnn
-
whs 0 5 ooooooo
-
whs 0 6 pppppp
-
Kickstart 0 8 xyz
-
Kickstart 0 9 898989898
-
Kickstart 0 12 mmp
-
Kickstart 0 13 qty
-
-
-
Many thanks for the help again
Here is what I get in the DEBUG window
RecordNo: 1 and Name: 'whs'
RecordNo: 8 and Name: 'Kickstart'
+++++++++++++++++
Below is actual TABLE
Name Cust_ID RecordNum Address
whs 0 1 ggggggggg
0 2 qqqqqqq
0 3 mmmmm
0 4 nnnnnnnnn
0 5 ooooooo
0 6 pppppp
Kickstart 0 8 xyz
0 9 898989898
0 12 mmp
0 13 qty
+++++++++++++++++++++++++
Looking through the code, I find the above result is LOGICAL as no values are being entered in to the
Name field from the Combo after the initial NEW Entry.
The code is looking for a higher Record number where
the NAME is the chosen name. There is all but ONE record for each name which is the FIRST record which satisfies the criteria.
Though I found and tried a routine to do this, I have abandoned it as it populates the pull down box with
same Name making it useless to select a customer quickly. I have since used the SORT DESC method to get the empty ones to the bottom.
I guess One way is to automatically Enter a Customer ID (a short name for example) at the same time as the ORIGINAL Name in a second field (not dependant on the Combo) and use the search routine you have proposed to find the highest record number.
What do you think ?
If the customerID corresponds uniquely to the name you can use that instead. Where [NAME] appears in the queries in my code replace with CustID. Change combobox to SELECT DISTINCT CustID, Name .. etc. Set the combobox field widths to 0cm; 3cm which will hide the CustID from the user. Keep the bound field to 1 and it should work. Any problems let me know.
Mary
+++++++++++++++++++++++++
Looking through the code, I find the above result is LOGICAL as no values are being entered in to the
Name field from the Combo after the initial NEW Entry.
The code is looking for a higher Record number where
the NAME is the chosen name. There is all but ONE record for each name which is the FIRST record which satisfies the criteria.
Though I found and tried a routine to do this, I have abandoned it as it populates the pull down box with
same Name making it useless to select a customer quickly. I have since used the SORT DESC method to get the empty ones to the bottom.
I guess One way is to automatically Enter a Customer ID (a short name for example) at the same time as the ORIGINAL Name in a second field (not dependant on the Combo) and use the search routine you have proposed to find the highest record number.
What do you think ?
If the customerID corresponds uniquely to the name you can use that instead. Where [NAME] appears in the queries in my code replace with CustID. Change combobox to SELECT DISTINCT CustID, Name .. etc. Set the combobox field widths to 0cm; 3cm which will hide the CustID from the user. Keep the bound field to 1 and it should work. Any problems let me know.
Mary
Is there a way to enter a customer ID derived from the Name automatically everytime a name is selected from the combo for a new record ?
Is there a way to enter a customer ID derived from the Name automatically everytime a name is selected from the combo for a new record ?
Use the DLookup function:
DLookup("[CustID]","Miracle_Cloth_Main","[Name]='" & Me.Name_Combo & "'")
Is there a way to enter a customer ID derived from the Name automatically everytime a name is selected from the combo for a new record ?
For Example -
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MYRS("Cust_ID")= An AUTONumber+ SHORT MyRS("Name")
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
Sorry, I understand now.
You're making life difficult for yourself trying to create an alpha numeric CustID. My advice is just add an Autonumber primary key and call it CustomerID. It will populate itself for all new records. Then use that as the foreign key in any table that currently has the [Name] as the foreign key.
Using the kind of combination you're suggesting is very difficult. How do you find the max number already entered to add 1 to (which is how you code an autonumber in VBA). You would have to break it apart each time to remove the shortname portion. It's a lot more trouble than it's worth. -
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MYRS("Cust_ID")= An AUTONumber+ SHORT MyRS("Name")
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
[/quote]
Sorry, I understand now.
You're making life difficult for yourself trying to create an alpha numeric CustID. My advice is just add an Autonumber primary key and call it CustomerID. It will populate itself for all new records. Then use that as the foreign key in any table that currently has the [Name] as the foreign key.
Using the kind of combination you're suggesting is very difficult. How do you find the max number already entered to add 1 to (which is how you code an autonumber in VBA). You would have to break it apart each time to remove the shortname portion. It's a lot more trouble than it's worth. -
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MYRS("Cust_ID")= An AUTONumber+ SHORT MyRS("Name")
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
[/quote]
OK I understand. So the Simple solution will be just to copy the NAME to the CUST ID Field -
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MYRS("Cust_ID")= MyRS("Name")
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
Is that a correct Syntax ?
OK I understand. So the Simple solution will be just to copy the NAME to the CUST ID Field
NO. The simple solution is to go to the table that MyRS is based on. Add a new field. Call it CustID (without the underscore to distinguish it) and set it's data type to Autonumber. Ideally you want to delete the existing Cust_ID field if it's not going to mess up your data too much.
Then in your code below you can ignore it completely as it is populated automatically every time a new record is added. -
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
NO. The simple solution is to go to the table that MyRS is based on. Add a new field. Call it CustID (without the underscore to distinguish it) and set it's data type to Autonumber. Ideally you want to delete the existing Cust_ID field if it's not going to mess up your data too much.
Then in your code below you can ignore it completely as it is populated automatically every time a new record is added.
Hello Mary,
I think I haven't made it clear.
To find the latest record you need the UNIQUE customer NAME to search and compare.
The Combo doesn't allow you to have a NAme associated with each record as technically it is not bound and doesn't fill the field.
If I then use the same NAME to bind to Customer ID (or any other field) I will have a searchable Unique VALE (Name) to find the latest record - I have tried the code below but get a Syntax error on
-
-
MyRS("Cust_ID") = MyRS("Name")
-
-
-
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MyRS("Cust_ID") = MyRS("Name")
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
Hi all.
Can I get an update on where this thread has reached? I have just spent some minutes reading through it, but it seems to have changed direction at least once or twice.
I believe the original question was how to have a field SUM'd across all prior records for the same ID, and provided on the form as default input value for another field. This seems quite straightforward, and should present no great difficulty for the Access masterminds here.
But now we seem to be buried in a maze of unique names and autonumbers and bound versus unbound fields, and so on. Could someone please summarise the outstanding problem, just to show that someone understands what the issue actually is? I suspect (or should I say hope :)) that I'm not the only one to have lost the plot here.
NeoPa 32,556
Expert Mod 16PB
Valley,
I'm sorry to say that this thread has become so complicated that most of us (that I've spoken with) find it difficult even to understand the question any more.
It is a complicated question (or series of them) where the information is not as clear as it could be.
It has certainly reached the stage where trying to give answers is too heavy a workload for a single thread. I personally tried another shot at it tonight and I felt myself getting quite depressed at only about half way through.
I do appreciate that you've tried to provide information where requested and so this is not really about criticism - just , in the real world, it has got too complicated to deal with.
I therefore don't think it is reasonable to expect any more interaction on this thread.
Having said all that, if you would like to formulate (very carefully as this is quite a complicated problem) a new thread, with all the relevant information laid out clearly in a single place, then I'm sure we would give it another go.
We would expect :
1. You to follow the guidelines laid out here POSTING GUIDELINES: Please read carefully before posting to a forum .
2. You to follow each response in order and deal with one thing at a time. If a problem is complicated, it nevertheless needs dealing with before progressing to another, as this makes it doubly difficult for an expert to find a sensible solution.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: David Messner |
last post by:
Ok I know this is simple but the statement eludes me...
I have a date field where I want the default value on the data entry form's
date field to be the last date entered. I figure I can do this...
|
by: Ray Holtz |
last post by:
I have a form that shows a single record based on a query criteria.
When I click a button it is set to use an append query to copy that
record to a separate table, then deletes the record from the...
|
by: Dixie |
last post by:
Can I set the Format property in a date/time field in code?
Can I set the Input Mask in a date/time field in code?
Can I set the Format of a Yes/No field to Checkbox in code?
I am working on...
|
by: erick-flores |
last post by:
Hello
I am trying to setup a default value for a field in a form. The field
is a text box. I need to setup the default value to: 0.000. And
whenever the user is trying to enter a value for this...
|
by: AA Arens |
last post by:
Hi I do have a products table and products-parts table in my Access
2003 database and log all services into a form.
I do have at least the following two combo boxes on my form:
- Choose...
|
by: Ecohouse |
last post by:
I have a main form with two subforms. The first subform has the child
link to the main form identity key.
subform1 - Master Field: SK
Child Field: TrainingMasterSK
The second subform has a...
|
by: Finn Stampe Mikkelsen |
last post by:
Hi
I have defined a table in my database, with 2 date-fields. I have set a
default value to DBNull. I have integrated a nullable datetimepicker control
to my project and set the apropriate...
|
by: thefredzx |
last post by:
i have a problem for aplication of apriori algorithm in datamining..my problem is how to make an additional field in database?
for example: I have some data like shown below:...
|
by: Brett_A |
last post by:
I have a form where the first field is a dynamic drop-down that pulls
from a db (Access). The fields associated with the query are task_id,
task_name and task_rate. The field has the value of...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |