Problems with VBA & Queries...!!?

masterkale

AuzSolutions
Local time
Tomorrow, 07:45
Joined
Sep 19, 2006
Messages
22
To start with if your going to explain anything... lets just say im a noob.. :)


I have a login form which passes the info to a sub routine in one of my modules...

Option Compare Database


Global MyStrUserId As String
Global MyStrUserActive As String
Global MyStrUserSecurityLevel As String

This info above is in the general declarations...i can access the stored (in memory) data that gets saved as global strings.

Now i can take this info and use it on other forms message boxs private subs etc etc...

But for the life of me HOW do i use this info in the where query statement...?!?!

Eg.

I have a query which displays records from a usermessages table. This query displays all the records based on the userid where userid = forms!frmmain.txtuserlogedin.value

what i want is where userid = MyStrUserId

but this doesn't work as the SQL engine does not see the global defined variable...???

Cheers
Tristan F
 
to use gbl variable in a query, you need to get the variable either onto a form, or into a function.

function is easiest

define a function

function readuserid as string

readuserid = nz(mystrguserid)

end function

now you can use the function as a query parameter, but you need parenthesis, so that in the condition you have =readuserid()

the nz function ensures a null string is converted to avoid type cast errors.

hope this helps
 
Thank you for the post was exactly what i was after......

There isn't a shorter way by any chance though...??
 

Users who are viewing this thread

Back
Top Bottom