I am use'n a form to enter customer and order information. If the customer allready exists, the form will auto fill in their Cust_ID and Email so that the user does not have to. If the customer does not exist, I am trying to make the form search through the current Cust_ID's and find the max, add 1, then enter that into the combobox on the form as the new customer's id. This is my current code:
'fill in email and cust_id if customer exists
Private Sub cmbcustomer_AfterUpdate()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
'check if customer exists
rs.FindFirst "Customer_Name = '" & [cmbcustomer].Value & "'"
If rs.NoMatch = False Then
Me.Bookmark = rs.Bookmark
[cmbcustid].Value = Cust_ID 'fill in cust_id
[cmbemail].Value = Email 'fill in email
Else
MsgBox "New Customer, Entering a new Customer ID"
[cmbcustid].Value = Max(Cust_ID) + 1 'enter new cust_id
End If
rs.Close
End Sub
The error I am getting is:
Compile error:
Sub or function not defined.
and it highlights the word Max in my
[cmbcustid].Value = Max(Cust_ID) + 1 line.
I'm not understanding why it's not letting me use the Max function here. I tried to set up a query to find the max Cust_ID, but that gives me problems trying to add 1 to a string varible. (string because I have to set the initial = to an sql statement) Any suggestions on how I could make Max work in this situation? I thought about make'n a private function named Max but I wasn't sure what I'd put there since it is usually a built in function.
-G78
'fill in email and cust_id if customer exists
Private Sub cmbcustomer_AfterUpdate()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
'check if customer exists
rs.FindFirst "Customer_Name = '" & [cmbcustomer].Value & "'"
If rs.NoMatch = False Then
Me.Bookmark = rs.Bookmark
[cmbcustid].Value = Cust_ID 'fill in cust_id
[cmbemail].Value = Email 'fill in email
Else
MsgBox "New Customer, Entering a new Customer ID"
[cmbcustid].Value = Max(Cust_ID) + 1 'enter new cust_id
End If
rs.Close
End Sub
The error I am getting is:
Compile error:
Sub or function not defined.
and it highlights the word Max in my
[cmbcustid].Value = Max(Cust_ID) + 1 line.
I'm not understanding why it's not letting me use the Max function here. I tried to set up a query to find the max Cust_ID, but that gives me problems trying to add 1 to a string varible. (string because I have to set the initial = to an sql statement) Any suggestions on how I could make Max work in this situation? I thought about make'n a private function named Max but I wasn't sure what I'd put there since it is usually a built in function.
-G78