LearnersPermit
Technical User
I have merged two databases, a clients database and a book orders database. I have now created an order form which is automatically opened with the client information from a form used to add new clients or look up current clients information. This part does work just fine.
I also have a subform used to order new books. The majority of the form works fine. It is the order # that is the problem. The order # is no longer an autonumber and I am using DMax in an attempt to force the order to form to select the next number. This has not been working. I receive the warning that the number cannot be a null. I have set the default for the order # to -1, 0 and 1, all without success.
The following is my code on the main form (the one that shows the client name and client ID).
Private Sub Form_Open(Cancel As Integer)
Dim Order_ID_Var As Long
Dim SQL As String
Order_ID_Var = -1
If (Nz(DMax("[Order_ID]", "[tblOrders]") = -1) Then
Order_ID_Var = 1
Else
Order_ID_Var = Nz(DMax("[Order_ID]", "[tblOrders]") + 1
End If
SQL = "INSERT INTO tblOrders (Order_ID, Client_ID) Values (" & Order_ID_Var & "," & Client_ID & " )"
CurrentDb.Execute SQL, dbFailOnError
End Sub
And I have used the following code on the subform.
Private Sub Form_Load()
Dim intNextNum As Variant
intNextNum = Nz(DMax("[Order_ID]", "[tblOrders]")
End Sub
ANY SUGGESTIONS?
Thanks in advance for your help
I also have a subform used to order new books. The majority of the form works fine. It is the order # that is the problem. The order # is no longer an autonumber and I am using DMax in an attempt to force the order to form to select the next number. This has not been working. I receive the warning that the number cannot be a null. I have set the default for the order # to -1, 0 and 1, all without success.
The following is my code on the main form (the one that shows the client name and client ID).
Private Sub Form_Open(Cancel As Integer)
Dim Order_ID_Var As Long
Dim SQL As String
Order_ID_Var = -1
If (Nz(DMax("[Order_ID]", "[tblOrders]") = -1) Then
Order_ID_Var = 1
Else
Order_ID_Var = Nz(DMax("[Order_ID]", "[tblOrders]") + 1
End If
SQL = "INSERT INTO tblOrders (Order_ID, Client_ID) Values (" & Order_ID_Var & "," & Client_ID & " )"
CurrentDb.Execute SQL, dbFailOnError
End Sub
And I have used the following code on the subform.
Private Sub Form_Load()
Dim intNextNum As Variant
intNextNum = Nz(DMax("[Order_ID]", "[tblOrders]")
End Sub
ANY SUGGESTIONS?
Thanks in advance for your help