Variable in another module

  • Thread starter Thread starter nexus
  • Start date Start date
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?
 
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
 
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
 
Back
Top