Simple problem for an experienced person to solve

Brian Martin

Registered User.
Local time
Today, 19:40
Joined
Jul 24, 2002
Messages
68
I have a form that displays a list of parts from the parts library table. beside each part is a button that when clicked starts a query that asks the user for the quantity of the part they need and then adds it to the separate parts list. However I want code in the button that checks whether the part chosen is already in the separate parts list and if so an update query is carried out that updates the quantity of the part in the separate list.
Something along the lines od the following but I'm just not quite sure how to write the code.

IF part number = list.part number THEN
openquery UpdateQuantity
ELSE
openquery AddPart
 
well....

Why not do a search....

Set a recordset to the source of the list and then do a findfirst on it. If rs.nomatch = false you are in business.... Would this not work?

Dim db As Database
Dim rs As DAO.Recordset
Dim strCriteria As String
Set db = CurrentDb()
Set rs = db.OpenRecordset(tblXXX, dbOpenDynaset) --> Your list table recorsource....
' This function will allow to search diferent fields...
strCriteria = vSearch (your text box)
If rs.EOF And rs.BOF Then
MsgBox "Table " & vTable & " is empty...", vbOKOnly, "Error"
End If
rs.MoveFirst
rs.FindFirst "[fldXXX] = " & strCriteria & ""
If rs.NoMatch Then
MsgBox "Did not find " & vSearch & " in table " & vTable, vbOKOnly, "Error"
Else
"Do your coding here...." I.E. openquery UpdateQuantity
End If

Regards,
 

Users who are viewing this thread

Back
Top Bottom