Click to See Complete Forum and Search --> : Run a query on Access97 db
rockies1
Aug 25th, 1999, 06:30 PM
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
rockies1@gvi.net
My Web Page (http://members.xoom.com/Rockies1)
chrisfricke
Aug 25th, 1999, 07:20 PM
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
rockies1
Aug 25th, 1999, 07:32 PM
Thank you very much!!
------------------
Morgan
rockies1@gvi.net
My Web Page (http://members.xoom.com/Rockies1)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.