E
Eric
Hope someone can help me here. (Access 97)
I have a combo box set up with a list of product codes
that a user can select from, or can type into the field. I
have some code set up where if the user selects a invalid
product code, it is supposed to generate a new record.
Well, it doesn't, and it is in a endless loop within the
code.
I need a SQL statement that will enter in a new product
code for me, but need some help with the statement. Here
is what I currently have now:
Private Sub cboProduct_AfterUpdate()
Dim Product As String, TarWgt As Double, FileNum As
Integer, strSQL As String, strMsg As String
On Error GoTo cboProduct_ErrorHandler
Product = Me.cboProduct.Value
'Find the File Number
FileNum = DLookup
("FileNumber", "tblProdSpecs", "Product = '" & Product
& "'")
Me.FileLocation.Value = FileNum
'Find the Product's Target Weight.
TarWgt = DLookup("Target", "tblProdSpecs", "Product
= '" & Product & "'")
Me.TargetWeight.Value = TarWgt
cboProduct_Exit:
Exit Sub
cboProduct_ErrorHandler:
If Err.Number = 94 Then
strMsg = MsgBox("The product, " &
Me.cboProduct.Value & ", cannot be located in the product
list. Do you wish to add this to the product list?",
vbYesNo)
If strMsg = vbYes Then
strSQL = "UPDATE tblProdSpecs SET
tblProdSpecs.FileNumber = 0 WHERE
(((tblProdSpecs.FileNumber) Is Null));" 'this does not
work, the endless loop since the filenumber <> 0 anywhere
in the table.
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Resume Next
Else
Resume cboProduct_Exit
End If
Else
MsgBox Err.Number & " " & Err.Description
Resume cboProduct_Exit
End If
End Sub
I have a combo box set up with a list of product codes
that a user can select from, or can type into the field. I
have some code set up where if the user selects a invalid
product code, it is supposed to generate a new record.
Well, it doesn't, and it is in a endless loop within the
code.
I need a SQL statement that will enter in a new product
code for me, but need some help with the statement. Here
is what I currently have now:
Private Sub cboProduct_AfterUpdate()
Dim Product As String, TarWgt As Double, FileNum As
Integer, strSQL As String, strMsg As String
On Error GoTo cboProduct_ErrorHandler
Product = Me.cboProduct.Value
'Find the File Number
FileNum = DLookup
("FileNumber", "tblProdSpecs", "Product = '" & Product
& "'")
Me.FileLocation.Value = FileNum
'Find the Product's Target Weight.
TarWgt = DLookup("Target", "tblProdSpecs", "Product
= '" & Product & "'")
Me.TargetWeight.Value = TarWgt
cboProduct_Exit:
Exit Sub
cboProduct_ErrorHandler:
If Err.Number = 94 Then
strMsg = MsgBox("The product, " &
Me.cboProduct.Value & ", cannot be located in the product
list. Do you wish to add this to the product list?",
vbYesNo)
If strMsg = vbYes Then
strSQL = "UPDATE tblProdSpecs SET
tblProdSpecs.FileNumber = 0 WHERE
(((tblProdSpecs.FileNumber) Is Null));" 'this does not
work, the endless loop since the filenumber <> 0 anywhere
in the table.
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Resume Next
Else
Resume cboProduct_Exit
End If
Else
MsgBox Err.Number & " " & Err.Description
Resume cboProduct_Exit
End If
End Sub