I have some issues with using recordsets that you may be able to help out on. Heres my senario:
form: frmStock
table: tblStock
table: tblProducts
On my (stock) form I have the ability to search for a product from the product table. Once I have returned the product value (eg Product Code) I can add it to the tblStock with other data such as inventory details etc.
I also have the ability to enter the product code directly into a field on the frmStock so that if the user knows the number, it will save him/her looking it up (its a time saving thing...).
I have written a small section of code to check to see if that manually typed code actually exists in my products table, and if it doesn't then to produce an error message. This is my code:
Its quite bizzare in the fact that even if I type a correct code into txtProductCode (i.e. the relating product exists in my table), I sitll have the result "Not Found" returned. Is there a problem with my code? I'm not that familiar with using recordsets so more than likely there will be issues!
TIA
form: frmStock
table: tblStock
table: tblProducts
On my (stock) form I have the ability to search for a product from the product table. Once I have returned the product value (eg Product Code) I can add it to the tblStock with other data such as inventory details etc.
I also have the ability to enter the product code directly into a field on the frmStock so that if the user knows the number, it will save him/her looking it up (its a time saving thing...).
I have written a small section of code to check to see if that manually typed code actually exists in my products table, and if it doesn't then to produce an error message. This is my code:
Code:
Function fProductCodeCheck()
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblProducts", dbOpenDynaset)
rst.MoveFirst
rst.FindFirst "ProductCode=" & txtProductCode 'ProductCode is the field on the table, txtProductCode the field on my form
If rst.NoMatch Then
MsgBox "Not found"
Else
MsgBox "Found 1 record: " & rst.Fields("Description") 'Description is a field within the tblProducts
End If
rst.Close
End Function
Its quite bizzare in the fact that even if I type a correct code into txtProductCode (i.e. the relating product exists in my table), I sitll have the result "Not Found" returned. Is there a problem with my code? I'm not that familiar with using recordsets so more than likely there will be issues!
TIA