Thanks,
the code: DoCmd.Close
DoCmd.OpenForm "frmAddProducts"
was a fix so that I didn't get the error.
TheAceMan1, tried your code and I now get a 'no current record error. It still seems like it don't know how to get to another record.
MaxEd the data entries is set to no.
EdSki there is on on open or onload with this form.
Here is the complete code for the form, maybe that will help. THANKS EVERYONE FOR THE HELP.
---------------------------------------------------------
Option Compare Database 'Use database order for string comparisons
Private Sub btnAddRecord_Click()
On Error GoTo Err_btnAddRecord_Click
DoCmd.GoToRecord , , A_NEWREC
Me![cbxProduct].Locked = False
Me!optionColorFam.Locked = False
Me![cbxProduct].TabStop = True
Me!optionColorFam.TabStop = True
Me![Part#] = " "
Me!tmpProdNo = ""
Me!tmpColorNo = ""
Me!ColorLow = ""
Me!ColorHigh = ""
Me!tmpNextColorNo = ""
Me!tmpPrefix = ""
Me!delno = ""
Me!delnow = ""
Me!cbxProduct.SetFocus
Exit_btnAddRecord_Click:
Exit Sub
Err_btnAddRecord_Click:
MsgBox Error$
Resume Exit_btnAddRecord_Click
End Sub
Private Sub btnSave_Click()
On Error GoTo Err_btnSave_Click
DoCmd.RunCommand acCmdSaveRecord
Exit_btnSave_Click:
Exit Sub
Err_btnSave_Click:
MsgBox Error$
Resume Exit_btnSave_Click
End Sub
Private Sub cbxProduct_Exit(Cancel As Integer)
On Error GoTo Err_cbxProduct_Exit
'Check to see if in "Add" mode
If Me![cbxProduct].Locked = False Then
'Make sure components to create a valid part # have been selected.
If Me!tmpProdNo = "" Then
MsgBox "You have not selected a Product. Please select one.", vbInformation, "ERROR, NO PRODUCT SELECTED"
DoCmd.CancelEvent
Me!cbxProduct.SetFocus
End If
End If
Exit_cbxProduct_Exit:
Exit Sub
Err_cbxProduct_Exit:
MsgBox Error$
Resume Exit_cbxProduct_Exit
End Sub
Private Sub cbxProductList_AfterUpdate()
On Error GoTo Err_cbxProductList_AfterUpdate
Me![Part#].SetFocus
DoCmd.FindRecord Me![cbxProductList]
Me![Color].SetFocus
Exit_cbxProductList_AfterUpdate:
Exit Sub
Err_cbxProductList_AfterUpdate:
MsgBox Error$
Resume Exit_cbxProductList_AfterUpdate
End Sub
Private Sub cbxProductList_Enter()
On Error GoTo Err_cbxProductList_Enter
DoCmd.RunCommand acCmdSaveRecord
Me!cbxProductList.Requery
Me!cbxProductList.Dropdown
Exit_cbxProductList_Enter:
Exit Sub
Err_cbxProductList_Enter:
MsgBox Error$
Resume Exit_cbxProductList_Enter
End Sub
Private Sub Form_AfterDelConfirm(Status As Integer)
If Status = acDeleteOK Then Me.Requery
End Sub
Private Sub Form_AfterInsert()
On Error GoTo Err_Form_AfterInsert
If Me!ProductDivision <> "Miscellanous" Then
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryupdatetblnextcolorno"
DoCmd.SetWarnings True
End If
Me![cbxProduct].Locked = True
Me!optionColorFam.Locked = True
Me![cbxProduct].TabStop = False
Me!optionColorFam.TabStop = False
Me!optionColorFam = ""
Me!tmpProdNo = ""
Me!tmpColorNo = ""
Me!ColorLow = ""
Me!ColorHigh = ""
Me!tmpNextColorNo = ""
Me!tmpPrefix = ""
Me!delno = ""
Me!delnow = ""
Exit_Form_AfterInsert:
Exit Sub
Err_Form_AfterInsert:
MsgBox Error$
Resume Exit_Form_AfterInsert
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate
If Len(Me![Description]) > "25" Then
MsgBox "Your Product Description is to long! You will have to abbreviate color name and/or abbreviate product name. (If product name needs to be shortened you will need to remove and reAdd the product.)", vbCritical, "ERROR, DESCRIPTION TO LONG"
Exit Sub
Me![Color].SetFocus
End If
Me!Description = Me!cbxProduct & " " & Me!Color & " " & Me![Color#]
Exit_Form_BeforeUpdate:
Exit Sub
Err_Form_BeforeUpdate:
MsgBox Error$
Resume Exit_Form_BeforeUpdate
End Sub
Private Sub optionColorFam_AfterUpdate()
On Error GoTo Err_optionColorFam_AfterUpdate
If optionColorFam = 1 Then
Me!ColorLow = "000"
Me!ColorHigh = "099"
ElseIf optionColorFam = 2 Then
Me!ColorLow = "100"
Me!ColorHigh = "199"
ElseIf optionColorFam = 3 Then
Me!ColorLow = "200"
Me!ColorHigh = "299"
ElseIf optionColorFam = 4 Then
Me!ColorLow = "300"
Me!ColorHigh = "399"
ElseIf optionColorFam = 5 Then
Me!ColorLow = "400"
Me!ColorHigh = "499"
ElseIf optionColorFam = 6 Then
Me!ColorLow = "500"
Me!ColorHigh = "599"
ElseIf optionColorFam = 7 Then
Me!ColorLow = "600"
Me!ColorHigh = "699"
ElseIf optionColorFam = 8 Then
Me!ColorLow = "700"
Me!ColorHigh = "799"
ElseIf optionColorFam = 9 Then
Me!ColorLow = "800"
Me!ColorHigh = "899"
ElseIf optionColorFam = 10 Then
Me!ColorLow = "900"
Me!ColorHigh = "989"
ElseIf optionColorFam = 11 Then
Me!ColorLow = "990"
Me!ColorHigh = "999"
End If
Me!tmpColorNo = DMin("Number", "qryAvailColorFam")
Exit_optionColorFam_AfterUpdate:
Exit Sub
Err_optionColorFam_AfterUpdate:
MsgBox Error$
Resume Exit_optionColorFam_AfterUpdate
End Sub
Private Sub cbxProduct_AfterUpdate()
On Error GoTo Err_cbxProduct_AfterUpdate
Me!tmpProdNo = Me!cbxProduct.Column(1)
Me!Description = Me!cbxProduct.Column(0)
Me!ProductDivision = Me!cbxProduct.Column(2)
Me!ProductLine = Me!cbxProduct.Column(3)
Me!optionColorFam.SetFocus
Exit_cbxProduct_AfterUpdate:
Exit Sub
Err_cbxProduct_AfterUpdate:
MsgBox Error$
Resume Exit_cbxProduct_AfterUpdate
End Sub
Private Sub Color_Exit(Cancel As Integer)
On Error GoTo Color_Exit_Err
Me!Description = Me!cbxProduct & " " & Me!Color & " " & Me![Color#]
Color_Exit_Exit:
Exit Sub
Color_Exit_Err:
MsgBox Error$
Resume Color_Exit_Exit
End Sub
Private Sub optionColorFam_Exit(Cancel As Integer)
On Error GoTo Err_optionColorFam_Exit
Dim stno As String
Dim stprefix As String
'Check to see if in "Add" mode
If Me![cbxProduct].Locked = False Then
'Make sure components to create a valid part # have been selected.
If Me!tmpProdNo = "" Then
MsgBox "You have not selected a Product. Please select one.", vbInformation, "ERROR, NO PRODUCT SELECTED"
DoCmd.CancelEvent
Me!cbxProduct.SetFocus
ElseIf Me!tmpColorNo = "" Then
MsgBox "You have not selected a Color Family. Please select one.", vbInformation, "ERROR, NO COLOR FAMILY SELECTED"
DoCmd.CancelEvent
Me!optionColorFam.SetFocus
Else
Me![Part#] = Trim(Me![tmpProdNo]) & Trim([tmpColorNo])
Me![AGENTPART#] = Me![Part#]
'Find the next color #
stno = DLookup("NextColorNo", "tblNextColorNo", "[ProductDivision]= forms!frmAddProducts!ProductDivision")
stprefix = DLookup("prefix", "tblNextColorNo", "[ProductDivision]= forms!frmAddProducts!ProductDivision")
If Me!ProductDivision = "Miscellanous" Then
Me![Color#] = " "
ElseIf Me!ProductDivision = "split" Then
Me![Color#] = stno
Me!tmpNextColorNo = stno + 1
Else
Me![Color#] = stprefix & stno
If Me!ProductDivision = "side leather" Then
If stno <> "9999" Then
Me!tmpNextColorNo = stno + 1
Me!tmpNextColorNo = Lpad([tmpNextColorNo], "0", 4)
Me!tmpPrefix = stprefix
Else
Me!tmpNextColorNo = "0000"
Me!tmpPrefix = AutoIncr(stprefix)
End If
ElseIf Me!ProductDivision = "Whole Hide" Then
Me!tmpNextColorNo = stno + 1
Me!tmpPrefix = stprefix
End If
End If
End If
End If
Exit_optionColorFam_Exit:
Exit Sub
Err_optionColorFam_Exit:
MsgBox Error$
Resume Exit_optionColorFam_Exit
End Sub
Private Sub Penetrated_AfterUpdate()
On Error GoTo Err_Penetrated_AfterUpdate
stlong = Len([Color#])
If Me!Penetrated <> True Then
If Right(Trim([Color#]), 1) > "9" Then
Me![Color#] = Left([Color#], stlong - 1)
End If
Else
If Right(Trim([Color#]), 1) <= "9" Then
Me![Color#] = Me![Color#] & "P"
End If
End If
Me!Description = Me!cbxProduct & " " & Me!Color & " " & Me![Color#]
Exit_Penetrated_AfterUpdate:
Exit Sub
Err_Penetrated_AfterUpdate:
MsgBox Error$
Resume Exit_Penetrated_AfterUpdate
End Sub
Private Sub btnDelete_Click()
On Error GoTo Err_btnDelete_Click
Dim stlong As String
Dim stDelno As String
Dim stno2del As String
Dim stDelPrefix As String
If Not IsNull(Me![Color#]) Then
stDelno = DLookup("NextColorNo", "tblNextColorNo", "ProductDivision=forms!frmAddProducts![ProductDivision]")
stDelPrefix = DLookup("prefix", "tblNextColorNo", "[ProductDivision]= forms!frmAddProducts!ProductDivision")
Me!delno = stDelno - 1
stlong = Len([Color#])
If Right(Trim([Color#]), 1) > "9" Then 'is there a P
Me!delnow = Left([Color#], stlong - 1) ' remove the P
Else
Me!delnow = Me![Color#]
End If
If Me![delnow] = stDelPrefix & "0000" Then
MsgBox "You need to inform IT department that you are deleting a 0000 number. They will need to adjust the numbering system BEFORE you add another product", vbInformation, "INFORM IT DEPARTMENT"
Else
If (stDelPrefix & delno) = Me!delnow Then
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryUpdateDecreasetblNextColorNo"
DoCmd.SetWarnings True
End If
End If
End If
If MsgBox("You will be deleting Part #: " & Me![Part#] & " If you want to continue with the deletion select OK.", vbOKCancel, "CONFIRM PART# DELETION") = vbOK Then
Me.AllowDeletions = True
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
Me.AllowDeletions = False
End If
' DoCmd.Close
' DoCmd.OpenForm "frmAddProducts"
Exit_btnDelete_Click:
Exit Sub
Err_btnDelete_Click:
MsgBox Err.Description
Resume Exit_btnDelete_Click
End Sub
----------------------------
Thanks,