Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a Variable to a Field in Table on OnChange property

Status
Not open for further replies.

VickyLeigh

Technical User
Sep 14, 2000
5
GB
I have a Form in which I want the OnChange property to run some VB code which sets a variable to a value from a Table

Thus I have something like

Dim variablehere as integer

set variablehere = DoCmd.RunSql "Select Field1 from Table1;"

The second bit doesn't work - can someone tell me the code that will set variablehere to Field1 (Note - there will only over be one record in Table1

Thanks for any help [sig][/sig]
 
Try this in your code.

Dim variablehere as integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Table1")
With rs
variablehere = !Field1
End With

Set db = Nothing [sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top