Retreive Variable Value from Module

G

geeves1293

Hello all again,

I am trying to retreive a value from a Module variable. The contents of the
module are:-

Public MySELLERID As Long

I know theres something in there because I can get it though a MsgBox, but I
would like to output this into a text field on a form.

Please, please could someone help before I pull my hair out.

Many Thanks

Geeves1293
 
M

Marshall Barton

geeves1293 said:
I am trying to retreive a value from a Module variable. The contents of the
module are:-

Public MySELLERID As Long

I know theres something in there because I can get it though a MsgBox, but I
would like to output this into a text field on a form.

What kind of module?

You can use the Load event (of the form with the display
text box) code like this.
For MySELLERID in a standard module:
Me.textbox = MySELLERID
If the MySELLERID variable is in a different form's module:
Me.textbox = Forms!yourotherform.MySELLERID
 
G

geeves1293

Thanks very much Marshall, that works a treat.

It was a std module by the way.

Just one more question, how do you get the same information in the criteria
part of a select query?

Thanks for your help again so far.

Geeves1293
 
D

Douglas J. Steele

Unfortunately, you can't refer to public variables in queries.

You'll have to create a function that returns the value of the public
variable, and then call the function.

Function GetMySELLERID() As Long

GetMySELLERID = MySELLERID

End Function
 
M

Marshall Barton

Just ONE more? ;-)

Depends on what you are doing with the query. If you are
using VBA code to construct the query or a WhereCondition
argument then concatente it:
stWhere = "somefield=" & MySELLERID
If you want to use it in a saved query, then you need to
create a public function in the module to return the value:
Public Function GetID()
GetID = MySELLERID
End Function
so the query can get its hands on the value:
... WHERE somefield = GetID()
Or, in the query designer, just:
GetID()
 
G

geeves1293

Thanks Marshall, its all working now. Its been a long day, time for beer now.

Graham



Marshall Barton said:
Just ONE more? ;-)

Depends on what you are doing with the query. If you are
using VBA code to construct the query or a WhereCondition
argument then concatente it:
stWhere = "somefield=" & MySELLERID
If you want to use it in a saved query, then you need to
create a public function in the module to return the value:
Public Function GetID()
GetID = MySELLERID
End Function
so the query can get its hands on the value:
... WHERE somefield = GetID()
Or, in the query designer, just:
GetID()
--
Marsh
MVP [MS Access]

Thanks very much Marshall, that works a treat.

It was a std module by the way.

Just one more question, how do you get the same information in the criteria
part of a select query?
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top