Here's my current dilemma:
I have a button on a form that when clicked opens another form in data entry mode via DoCmd.OpenForm and the acFormAdd mode. However what I would like to happen after update of the productID field of the newly opened data entry form is that if a productID entered already exists I would like that same form to change data entry mode to false and display the record of the existing productID and allow it to be edited or saved.
Currently when try to simply set the data entry mode to false and use OpenRecordset to display the record associated with the productID entered I get 3022 duplicate entry errors.
Here is the AfterUpdate code for the productID field, its not finished so I'm sure there are probably syntax issues etc.:
Code:
Dim product As StringDim crit As String
Dim msg As String
Dim db As Database
Dim rst As Recordset
Dim SQLstr As String
Set db = CurrentDb
product = Me.prodID.Value
crit = "[prodID] = '" & product & "'"
If Me.prodID = DLookup("[prodID]", "tblProducts", crit) Then
msg = MsgBox("This record already exists, would you like to view it?", vbYesNo)
If msg = vbYes Then
SQLstr = "SELECT tblProducts.prodID, tblProducts.prodTypeID, tblProducts.prodDescription FROM tblProducts " & _
"WHERE (((tblProducts.prodID)= '" & product & "'));"
Set rst = db.OpenRecordset(SQLstr, dbOpenDynaset)
rst.MoveFirst
Me.prodID = rst.Fields("prodID").Value
Me.prodDescription = rst.Fields("prodDescription").Value
Me.prodType = rst.Fields("prodTypeID").Value
Me.prodID.SetFocus
Else
Resume Next
End If
End If
Set rst = Nothing
Set db = Nothing
End Sub