For the initial question ...
You need to add a where clause e.g.
strQuery = "SELECT * FROM test.dbf WHERE BAR_CODE = '" + strAnswer + "'"
Note this will be open to SQL Injection - you're better off using oledb parameters (but I don't know how to do this in vbscript) or having a stored procedure to return the data.
For the follow-up question
Quote:
after i enter the bar code i have to press OK button or ENTER,is there any way to make it continuous? i mean after entering the bar code the data of the PRN_STATE will be deleted and the box message will remain waiting for the new bar code.
You can use a WHILE loop e.g.
While strAnswer <> "Q"
strAnswer = InputBox("Please enter the barcode, or Q to quit:", "Search")
End While
[EDIT after OP comment]
Be careful where you put the loop beginning and end e.g.
Dim cn
Dim strConn
Dim rs
Dim strQuery
Dim f, strFields
Dim strAnswer
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Users\Shadi\Desktop;" & _
"Extended Properties=dBase IV;"
While strAnswer <> "Q"
strAnswer = InputBox("Please enter the barcode, or Q to quit:", "Search")
cn = CreateObject("ADODB.Connection")
cn.Open(strConn)
rs = CreateObject("ADODB.Recordset")
'Remember to fix this to remove the SQL Injection vulnerability
strQuery = "SELECT * FROM test.dbf where BAR_CODE='" & strAnswer & "'"
rs.CursorLocation = 3
rs.Open(strQuery, cn, 3, 3)
With rs
MsgBox("Full Name: " & .Fields("FULL_NAME").Value)
MsgBox("Card_ID: " & .Fields("CARD_ID").Value)
MsgBox("PRN_STATE: " & .Fields("PRN_STATE").Value)
.Fields("PRN_STATE").Value = " "
.Update()
End With
rs.Close()
cn.Close()
End While
rs = Nothing
cn = Nothing