Code:
Private Sub Command22_Click()
Dim tProducts As DAO.Recordset
Set tProducts = CurrentDb.OpenRecordset("SELECT * FROM tProducts")
If Me.tProductLine.Value = 1 Then
Dim SQL1 As Integer
Dim Code1 As Integer
Dim NewID1 As String
SQL1 = DMax("ProductCode", "tProducts", "ProductLine=1")
Code1 = SQL1 + 1
tProducts.AddNew
tProducts![ProductCode] = Code1
NewID1 = "01" & Format(Code1, "00000")
tProducts![ItemCode] = NewID1
Else
If Me.tProductLine.Value = 2 Then
Dim SQL2 As Integer
Dim Code2 As Integer
Dim NewID2 As String
SQL2 = DMax("ProductCode", "tProducts", "ProductLine=2")
Code2 = SQL2 + 1
tProducts.AddNew
tProducts![ProductCode] = Code2
NewID2 = "02" & Format(Code2, "00000")
tProducts![ItemCode] = NewID2
Else
If Me.tProductLine.Value = 3 Then
Dim SQL3 As Integer
Dim Code3 As Integer
Dim NewID3 As String
SQL3 = DMax("ProductCode", "tProducts", "ProductLine=3")
Code3 = SQL3 + 1
tProducts.AddNew
tProducts![ProductCode] = Code3
NewID3 = "03" & Format(Code3, "00000")
tProducts![ItemCode] = NewID3
Else
If Me.tProductLine.Value = 4 Then
Dim SQL4 As Integer
Dim Code4 As Integer
Dim NewID4 As String
SQL4 = DMax("ProductCode", "tProducts", "ProductLine=4")
Code4 = SQL4 + 1
tProducts.AddNew
tProducts![ProductCode] = Code4
NewID4 = "04" & Format(Code4, "00000")
tProducts![ItemCode] = NewID4
Else
If Me.tProductLine.Value = 5 Then
Dim SQL5 As Integer
Dim Code5 As Integer
Dim NewID5 As String
SQL5 = DMax("ProductCode", "tProducts", "ProductLine=5")
Code5 = SQL5 + 1
tProducts.AddNew
tProducts![ProductCode] = Code5
NewID5 = "05" & Format(Code5, "00000")
tProducts![ItemCode] = NewID5
Else
If Me.tProductLine.Value = 6 Then
Dim SQL6 As Integer
Dim Code6 As Integer
Dim NewID6 As String
SQL6 = DMax("ProductCode", "tProducts", "ProductLine=6")
Code6 = SQL6 + 1
tProducts.AddNew
tProducts![ProductCode] = Code6
NewID6 = "06" & Format(Code6, "00000")
tProducts![ItemCode] = NewID6
Else
If Me.tProductLine.Value = 7 Then
Dim SQL7 As Integer
Dim Code7 As Integer
Dim NewID7 As String
SQL7 = DMax("ProductCode", "tProducts", "ProductLine=7")
Code7 = SQL7 + 1
tProducts.AddNew
tProducts![ProductCode] = Code7
NewID7 = "07" & Format(Code7, "00000")
tProducts![ItemCode] = NewID7
Else
If Me.tProductLine.Value = 8 Then
Dim SQL8 As Integer
Dim Code8 As Integer
Dim NewID8 As String
SQL8 = DMax("ProductCode", "tProducts", "ProductLine=8")
Code8 = SQL8 + 1
tProducts.AddNew
tProducts![ProductCode] = Code8
NewID8 = "30" & Format(Code8, "00000")
tProducts![ItemCode] = NewID8
Else
If Me.tProductLine.Value = 9 Then
Dim SQL9 As Integer
Dim Code9 As Integer
Dim NewID9 As String
SQL9 = DMax("ProductCode", "tProducts", "ProductLine=9")
Code9 = SQL9 + 1
tProducts.AddNew
tProducts![ProductCode] = Code9
NewID9 = "40" & Format(Code9, "00000")
tProducts![ItemCode] = NewID9
Else
If Me.tProductLine.Value = 10 Then
Dim SQL10 As Integer
Dim Code10 As Integer
Dim NewID10 As String
SQL10 = DMax("ProductCode", "tProducts", "ProductLine=10")
Code10 = SQL10 + 1
tProducts.AddNew
tProducts![ProductCode] = Code10
NewID10 = "50" & Format(Code10, "00000")
tProducts![ItemCode] = NewID10
Else
If Me.tProductLine.Value = 11 Then
Dim SQL11 As Integer
Dim Code11 As Integer
Dim NewID11 As String
SQL11 = DMax("ProductCode", "tProducts", "ProductLine=11")
Code11 = SQL11 + 1
tProducts.AddNew
tProducts![ProductCode] = Code11
NewID11 = "60" & Format(Code11, "00000")
tProducts![ItemCode] = NewID11
Else
If Me.tProductLine.Value = 12 Then
Dim SQL12 As Integer
Dim Code12 As Integer
Dim NewID12 As String
SQL12 = DMax("ProductCode", "tProducts", "ProductLine=12")
Code12 = SQL12 + 1
tProducts.AddNew
tProducts![ProductCode] = Code12
NewID12 = "70" & Format(Code12, "00000")
tProducts![ItemCode] = NewID12
Else
If Me.tProductLine.Value = 13 Then
Dim SQL13 As Integer
Dim Code13 As Integer
Dim NewID13 As String
SQL13 = DMax("ProductCode", "tProducts", "ProductLine=13")
Code13 = SQL13 + 1
tProducts.AddNew
tProducts![ProductCode] = Code13
NewID13 = "90" & Format(Code13, "00000")
tProducts![ItemCode] = NewID13
Else
MsgBox "You Must enter a Product Line in order to submit a new product!", vbOKOnly, "#ERROR!"
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
tProducts![ItemDescription] = Me.tItemDescription.Value
tProducts![UoM] = Me.tUoM.Value
tProducts![ProductLine] = Me.tProductLine.Value
tProducts![Aquisition] = Me.tAquasition.Value
tProducts![Active] = Me.ynActive.Value
tProducts![BOMRequired] = Me.ynBOM.Value
tProducts![AssemblyRequired] = Me.ynAss.Value
tProducts![Component] = Me.ynComponent.Value
tProducts![CoARequired] = Me.ynCoA.Value
tProducts.Update
DoCmd.Requery
tProducts.Close
DoCmd.Close
End Sub
the only thing I can imagine is that i have the form property DataEntry set to "Yes" so that when it pops up it shows up as a blank form. Could this be whats causing the duplicate entry? if so how do i fix that. If the code is the problem, please help me fix it.