Results 1 to 3 of 3

Thread: Simple Database question maybe?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    WALES UK
    Posts
    31

    Post

    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

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    This is DAO

    Set MySnapshot = MyDB.CreateSnapshot("Select * From details where MyDatabaseField = '" _
    & Text1.Text & "'")

    Text1.Text contains "Rhys"

    ------------------
    Marty
    HASTE CUISINE
    Fast French food.

  3. #3
    Member
    Join Date
    Jan 2000
    Location
    Southbridge, MA, USA
    Posts
    40

    Post

    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)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width