Results 1 to 3 of 3

Thread: Run a query on Access97 db

  1. #1

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375

    Post

    I've never done much database work with VB, but I need to do the following:

    Have users enter 2 numbers in text boxes. Then run a query on an access table where it returns all data between those 2 numbers.

    Can someone point me in the right direction?

    Thanks!!

    ------------------
    Morgan
    [email protected]
    My Web Page

  2. #2
    Lively Member
    Join Date
    Jan 1999
    Location
    Lincolnshire, UK
    Posts
    111

    Post

    You'll have to modify this code to suit your database, but here goes

    have the two text boxes called text1 and text2.

    Enter the following code in the event you are going to use to query the data base (eg a button click)

    dim sql as string
    dim mydatabase as database
    dim myrecordset as recordset

    set mydatabase = opendatabase("path to the database",false,false)

    sql="Select * from mytable where myfield1>=" & val(text1.text) & " and myfield2>=" & val(text2.text)
    set myrecordset = mydatabase.openrecordset(sql)

    now just use the myrecordset object the same as a VB data control.

    Remember that if you want to use the recordset outside of this procedure you'll have to publicly declare it at the top of the module or form

    Cheers

    Chris

  3. #3

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375

    Post

    Thank you very much!!

    ------------------
    Morgan
    [email protected]
    My Web Page

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