Hello fellows,
I,m stuck on this form and button for a while and have tried varies
methods but was unable to resolve the issue with my knowledge of vb in
access.
I have a form with a unbound text field (txtsearch) where staff enters
CustId (dmbarcode) and then click on a cmdbutton(check) which should
populate another form with the customer details which works fine if I
have a docmd.openform function but when I try to add some exception
handling into it, the error displays with "match not found for:
txtsearch" which I added in the code at the end against ELSE.
Testing:
Just to figure out what the dbopenrecordset is picking up from the
field dmbarcode in tbl_SO Cust Master, I changed the code in the ELSE
error from ScanBarcodeSearch to Dmbarcodecheck and turns out that it
picks out the first record only of the field in the table.
But I need to check the whole field to find a match and display the
details in the next form or display error with no match found.
Private Sub Check_Click()
Dim db As DAO.Database
Dim snp As DAO.Recordset
Dim Dmbarcodecheck As String
Dim ScanBarcodeSearch As String
ScanBarcodeSearch = Me.TXTSearch
Set db = CurrentDb
Set snp = db.OpenRecordset("SO Cust Master", dbOpenSnapshot)
Dmbarcodecheck = snp!DMBarcode
snp.Close
db.Close
ScanBarcodeSearch = Me.TXTSearch
If ScanBarcodeSearch = Dmbarcodecheck Then
MsgBox "Match Found For: " & ScanBarcodeSearch, , "Customer Found!"
DoCmd.OpenForm "search", acNormal, "", "[SO Cust Master].DMBarcode=" &
"'" & Me.TXTSearch & "'", acEdit, acNormal
DoCmd.Close acForm, "paratest"
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & ScanBarcodeSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
TXTSearch.SetFocus
End If
End Sub
Thanks in Advance,
Please help me out here as I need to finish the apps by Friday.
|