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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Variable via Query

Status
Not open for further replies.

BSSME

MIS
Dec 8, 2005
16
US
Hi All,

I want to set a public (global) variable via a query in VBA for Access. I have an idea like this:

Code:
 Dim SomeNum as Integer

SomeNum = "Select sometable.field from sometable where sometable.field=Form!frmform!field

I think I'm close, but something is missing or I may be way off. Any help would be greatly appreciated.
 
Have a look at the DLookUp function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I checked this out but now I get a "previous action cancelled" error.

Code:
Private Sub Form_Open(Cancel As Integer)

Dim SecLev As Integer
cboSombox.Requery

SecLev = DLookup("[SecurityLevel]", "tblUsers", "[UserN]=" _
& Forms!frmLogin!txtUser)


End Sub

Any idea what I'm doing wrong here?
 
If UserN is not defined as numeric in tblUsers:
SecLev = DLookup("[SecurityLevel]", "tblUsers", "[UserN][tt]=[!]'[/!]"[/tt] _
& Forms!frmLogin!txtUser [tt][!]& "'"[/!])[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I tried the edits as suggested however, I'm still getting an Out of Context value on the variable.

What I need is to reference a table using the user name txt box to select the appropriate record from the table. Then I want the variable to be set to the SecurityLevel which is any number from 1 - 10 for that user.

Thanks for your help thus far!

 
Is Forms!frmLogin!txtUser already populated when you call the DLookUp function ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top