visual basic code:
Private Sub cmdCheckCurrentRecord_Click()
Dim con As ADODB.Connection
Set con = New ADODB.Connection
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\exercise.mdb"
Set rst = Execute_SQL_ReturnRecordSet("Select * from Item", False, "C:\exercise.mdb")
rst.MoveFirst
Do While rst.EOF = False
If UserForm1.txtqty.Text = rst.Fields("Item_Code").Value Then
Exit Do
End If
rst.MoveNext
Loop
TextBox3.Text = rst.Fields("Qty")
Application.ScreenRefresh
End Sub
When I select item no 1, then when I press "Check Current Stock" it show its Qty...BUT, when I select other item numbers, let say item code number 3 it still show the Qty for item number 1...???....
From what are you selecting the item? A combo box? Listbox? What?
It would appear you would need to add a WHERE clause in your SELECT statement to uniquely identify the specific item and gets its quantity, but I don't know how you are making your selection as it is.
Sorry...when I changed the fieldname with Item_Code...there is a new error message:
Run Time Error 3021: Either BOF or EOF is True, or the current record has been deleted. Requested operations requires a current record. And "rst.MoveFirst" was yellow highlight....