Public Variable - Not working. Please help :)

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

Guest

I have had an awful time getting a public variable to work in my DB.
All I want to do is transfer a text value from one form to another.
So my user will start on the initial form, at which point they enter a
Social Security Number as part on the basic patient information. The SSN is
very important as it makes up component keys for pretty much every other
table in the DB. As such, when I open a new form to enter an address for the
patient, I really need to transfer this SSN along with it. So far my code is
something like such:

Standard Module:

Public Social_Security_Number as string


Initial Form (FRM_Patient_Basic):
(this is on TXT_Social_Security_Number.Exit)

Set Social_Security_Number = TXT_Social_Security_Number.Text

Address Form (FRM_Patient_Address):

Form_Load

TXT_Social_Security_Number.Text = Social_Security_Number

*Note, both Forms have a Control named TXT_Social_Security_Number

Any help you could give me would be greatly appreciated.

Thanks!
 
I should also have mentioned what happens.
In FRM_Patient_Address, the Public Variable Social_Security_Number doesn't
seem to be recognized.
Even a simple msgbox (Social_Security_Number) will come up blank.

Thanks again.
 
Kris L. said:
I have had an awful time getting a public variable to work in my DB.
All I want to do is transfer a text value from one form to another.
So my user will start on the initial form, at which point they enter a
Social Security Number as part on the basic patient information. The
SSN is very important as it makes up component keys for pretty much
every other table in the DB. As such, when I open a new form to
enter an address for the patient, I really need to transfer this SSN
along with it. So far my code is something like such:

Standard Module:

Public Social_Security_Number as string


Initial Form (FRM_Patient_Basic):
(this is on TXT_Social_Security_Number.Exit)

Set Social_Security_Number = TXT_Social_Security_Number.Text

Address Form (FRM_Patient_Address):

Form_Load

TXT_Social_Security_Number.Text = Social_Security_Number

*Note, both Forms have a Control named TXT_Social_Security_Number

Any help you could give me would be greatly appreciated.

Thanks!

In the first place, this line:
Set Social_Security_Number = TXT_Social_Security_Number.Text

is incorrect -- the "Set" keyword is inappropriate, and you really
shouldn't be using the .Text property either, though that isn't exactly
wrong; it's just that the Value property (which is the default property
of a text box) is usually what you are interested in with Access
controls. Now, since it is possible that value will be Null, I suggest
you use this line instead:

Social_Security_Number = TXT_Social_Security_Number & vbNullString

In the second place, I question your use of the Exit event for this
logic. What happens if the user never tabs into the text box, whether
because they manually skip over it for a new record or because they are
reviewing an existing record and the SSN has already been filled in?
I'd suggest capturing the intial value for each record in the form's
Current event, and then capturing any changed value for it in the text
box's AfterUpdate event.
 
Thanks for your response!

I'll try this when I get home.

To answer some of your questions:

All of the forms they can open check the SSN before opening the form,
thereby requiring that they enter a valid SSN.
Also, I believe when they click on the command button to open the new forms
it will remove focus from the text box, thereby going through the Exit
command.
Regardless, you could be right anyway and I'll need to test to make sure
that part works properly.
For now though, if I can get this variable to pass, I'll be in good shape.

thanks again!

Kris
 
Kris L. said:
To answer some of your questions:

All of the forms they can open check the SSN before opening the form,
thereby requiring that they enter a valid SSN.
Also, I believe when they click on the command button to open the new
forms it will remove focus from the text box, thereby going through
the Exit command.

That is true, provided that other circumstances force the focus to be in
the SSN text box originally.
Regardless, you could be right anyway and I'll need to test to make
sure that part works properly.
For now though, if I can get this variable to pass, I'll be in good
shape.

Good luck!
 
Back
Top