As stated above I am bit stuck whit search query I have used the code from the tutorial on this forum to connect the access file and display data from the table which works fine, where I am getting stuck is when I use this code:
I get the result which is the first record in a table always but not what I have searched for. If anybody knows what I am doing wrong please help!Code:Private Sub txtSearch_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then frmDisplay.Show Unload Me frmDisplay.lstResult.Clear Dim strSQL As String 'build the SQL statement based on what the user typed in txtSearch strSQL = "SELECT * FROM Data" If txtSearch.Text <> "" Then strSQL = strSQL & " WHERE Name = " & Val(txtSearch.Text) End If 'close the recordset (required before reloading it) ar.Close 'load the new data ar.Open strSQL, ac, adOpenKeyset, adLockPessimistic, adCmdText 'show the data frmDisplay.lstResult.AddItem ar.Fields("Name") frmDisplay.lstResult.AddItem ar.Fields("Surname") frmDisplay.lstResult.AddItem ar.Fields("Tel") frmDisplay.lstResult.AddItem ar.Fields("Mobile") frmDisplay.lstResult.AddItem ar.Fields("Firma") frmDisplay.lstResult.AddItem ar.Fields("EMail") frmDisplay.lstResult.AddItem ar.Fields("Address") frmDisplay.lstResult.AddItem ar.Fields("Web") frmDisplay.lstResult.AddItem ar.Fields("Account") End If End Sub




Reply With Quote