-
How can I search a field in a database when the user clicks on a cmd button?
For example if they wanted to find the name Rhys in a Table called details in a database called MyDatabase..
Assuming that they wrote it into a text area so the button would read the text box then check the database
I know this is easy but I cant get it to work.....
Cheers
Rhys :p
-
This is DAO
Set MySnapshot = MyDB.CreateSnapshot("Select * From details where MyDatabaseField = '" _
& Text1.Text & "'")
Text1.Text contains "Rhys"
------------------
Marty
HASTE CUISINE
Fast French food.
-
I am assuming you have a database which you have identified with dbName...
Dim db As Database
Dim qdf As QueryDef
Dim rst As Recordset
Dim mySQL As String
Dim result as String
' Define the SQL statement
mySQL = "SELECT * FROM tblName WHERE tblName.Item = '" & TextBox.Text & "'"
' Open a database from which to create the QueryDef object
Set db = OpenDatabase(dbName)
' Create a QueryDef object to retrieve the data
Set qdf = db.CreateQueryDef("")
With qdf
.SQL = mySQL
Set rst = .OpenRecordset()
If Not rst.EOF Then rst.MoveLast
If Not rst.BOF Then rst.MoveFirst
End With
result = rst.Fields(fieldName)