Public Variable Woes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to do something very simple and have been having loads of trouble
with it. I have two forms, between which I would love to pass a variable.
So far my efforts have been centered around using a public variable. The
code I use is this:

Mod_Global_Variables (Standard Module):

Public Social_Security_Number As String

FRM_Patient_Basic (Main Form)

Private Sub TXT_Social_Security_Number_Exit(Cancel As Integer)

Social_Security_Number = Trim(TXT_Social_Security_Number.Value)

End Sub

Now I know that the variable is being assigned because I am running a check
before I open the second form and it is returning the value.

Secondary Form (FRM_Patient_Address):

Private Sub Form_Load()

Me.Modal = True
Me.DataEntry = True
Me.NavigationButtons = False

TXT_Social_Security_Number.Value = Social_Security_Number
TXT_Social_Security_Number.SetFocus
TXT_Social_Security_Number.Text = Social_Security_Number

End Sub

This does not seem to work and the variable never seems to get passed which
a quick MSGBOX check on Social_Security_Number makes obvious.

Any suggestions??

THanks a Lot!
Kris
 
You can use the OpenArgs argument of the OpenForm method instead. Open your
second form like this:

DoCmd.OpenForm strFormName, acNormal, , , acFormAdd, acDialog,
txt_Social_Security_Number.Value

Then in the Open event of the second form:

Me.txtSSN.SetFocus

Then:

Private Sub txtSSN_GotFocus()
On Error Resume Next
If Me.NewRecord = True Then
Me.txtSSN = Me.OpenArgs
Me.txtSSN.SelStart = Me.txtSSN.SelLength + 1
End If
End Sub

I know this will work because I wrote code like this last week.

Now, can I talk you out of using SSNs in a non-payroll database. There are
millions of fraudulent ones, millions of wrong ones used by illegal aliens
to get employed, millions of mistakes, and probably millions like myself who
won't give one, or if forced will make one up.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Thanks for the tip!

I entered this code into my DB, but I still dont see how I actually pass the
value.... what code do I enter to actually assign the value from
Social_Security_Number to txt_Social_Security_Number in my second form?

Thx again!!
 
Kris L. said:
I'm trying to do something very simple and have been having loads of
trouble with it. I have two forms, between which I would love to
pass a variable. So far my efforts have been centered around using a
public variable. The code I use is this:

Mod_Global_Variables (Standard Module):

Public Social_Security_Number As String

FRM_Patient_Basic (Main Form)

Private Sub TXT_Social_Security_Number_Exit(Cancel As Integer)

Social_Security_Number = Trim(TXT_Social_Security_Number.Value)

End Sub

Now I know that the variable is being assigned because I am running a
check before I open the second form and it is returning the value.

Secondary Form (FRM_Patient_Address):

Private Sub Form_Load()

Me.Modal = True
Me.DataEntry = True
Me.NavigationButtons = False

TXT_Social_Security_Number.Value = Social_Security_Number
TXT_Social_Security_Number.SetFocus
TXT_Social_Security_Number.Text = Social_Security_Number

End Sub

This does not seem to work and the variable never seems to get passed
which a quick MSGBOX check on Social_Security_Number makes obvious.

Any suggestions??

THanks a Lot!
Kris

I wonder, Kris, whether your text box "TXT_Social_Security_Number" -- on
one form or the other -- is bound to a field named
"Social_Security_Number"? If so, when you refer to
Social_Security_Number on your form, Access will assume that it's the
field that you are referring to, and so the global variable of that name
will not be used.

If this is the problem, change the name of the global variable to
something like "gstrSocial_Security_Number", both in its declaration and
everywhere in code that you intend to refer to the variable.
 
OpenArgs is the 7th argument in the OpenForm method, you define it by simply
putting it there:

DoCmd.OpenForm "FormName",,,,,,txt_Social_Security_Number.Value

Its value is passed to the new textbox in this line of code:

Me.txtSSN = Me.OpenArgs
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access

Kris L. said:
Thanks for the tip!

I entered this code into my DB, but I still dont see how I actually pass the
value.... what code do I enter to actually assign the value from
Social_Security_Number to txt_Social_Security_Number in my second form?

Thx again!!
onMouseOut="window.status='';" oncontextmenu="window.status=''; return
true;"
onclick="location.href='http://www.enhancemysearch.com/admin/results.php?q=w
onMouseOver="window.status='' ; return true;"
onMouseOut="window.status='';" oncontextmenu="window.status=''; return
true;"
onclick="location.href='http://www.enhancemysearch.com/admin/results.php?q=L
onMouseOut="window.status='';" oncontextmenu="window.status=''; return
true;"
onclick="location.href='http://www.enhancemysearch.com/admin/results.php?q=w
 

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

Back
Top