|
-
Jun 14th, 2004, 05:31 AM
#1
Thread Starter
Lively Member
Newbie Q: Retrieve values stored in a module (Access 2000)
Hi.
I have a module with the following:
Option Compare Database
Public strMyName As String
strMyName takes the value of a text field on a form after I click a command button:
strMyName = Me.cboFirstname.Value
The Q is, how do I collect the value of strMyName and use throughout the application (in form lables etc).
Thanks,
jb
-
Jun 14th, 2004, 06:49 AM
#2
PowerPoster
I think you have 3 choices:
1. Just hide the form and done't close it. Then refer to the field (ie; formname.fieldname.text)
2. Create a Global variable in a module and move the value to there
3. Create a public variable on the form and hide the form.
-
Jun 14th, 2004, 06:58 AM
#3
On the On_Load event of the form put
In a module, define a public sub FillForm:
VB Code:
public sub FillForm(byref frmMe as form)
frmMe.lblMyName.caption = strMyName
end sub
Something like that, with a label lblMyName on each form you place the fillform call on.
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jun 14th, 2004, 07:17 AM
#4
Thread Starter
Lively Member
Thanks for the help guys.
I'm working with the code suggested by ecniv, just to expand, how would I then retrieve that value and use in a query to filter on firstnames for example:
strMyName = "James"
SELECT * FROM tblUsers WHERE Firstname = [strMyName]
strMyName being a public sub in a module
Thanks again
jb
-
Jun 14th, 2004, 08:27 AM
#5
Depends if you are setting that sql statement via code (string manipulation) or via query/query builder (need a function).
Sql statement - code
Code:
strSql = "select blah from blah where blah='" & strMyName &"'"
Note the single quotes - for more info see the second sticky post on the forum lists.
In a query
VB Code:
public function GetMyName() as string
GetMyName = strMyName
end function
In the query builder - where clause part put - GetMyName
Note: This should work in Access, but not in Sql server etc..
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|