Variable in another module

N

nexus

I have declared a variable in this module Main Menu, say

Public Sub Exit_Click()
Dim strTest as String
End Sub

(imagine there's a value to strTest)

Now i wan to store this variable in another module,
Enquiry Form. The enquiry page has a textbox called
txtEnqNo and i wan the variable strTest to be display in
the txtEnqNo during form view. How do i do that?
I tried putting these codes under the Enquiry form

strTest = Forms!frmEnqMain!txtEnqNo

but it doesnt work. Is there any way i can solve this?
 
A

Alex Dybenko

to set variable value strTest to value of texbox - syntax is correct
strTest = Forms!frmEnqMain!txtEnqNo
just make just you fist test textbox to null value, else you get error

to set textbox to variable value - you can make a public function in common
module, which returns a value of variable, and then in textbox control
source write:
=GetMyVar()

public function GetMyVar()
GetMyVar=strtest
end function

in this case strTest should be bublic also, or at least declared at this
module level
 
P

Peter De Baets

Perhaps you need to declare a public variable in a module.

Go to the modules tab, click new, and enter

Public gstrTest as string

(the "g" means global)

"gstrTest" is now a global variable and you can refer to it in any module.

Hope this helps,

Peter De Baets
Peter's Software - MS Access Tools for Developers
http://www.peterssoftware.com
 

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