Form Variable no longer passes to new form

B

Bmusgrove

Button Command39 on main form, when clicked opens the SWLicensesForm. Button
WinXP_Click() on the SWLicensesform, when clicked adds a new record and
fills in some fields for me. My problem is in the POTEMP and NuaNumTmp
variables being passed from the main form to th SwLicensesform.. These are
no longer being passed from the main form to the SWLicensesform, and I can
not fiure out why. I have a backup of the database that is about 8 days old
that works fine. The only thing I have done between the backup and the
variables not working is to compact the database. There are no error
messages, and I am at a loss to determine why the variables are being
destroyed or how to determine why.

On the main form

Private Sub Command39_Click()
On Error GoTo Err_Command39_Click


Dim stDocName As String
Dim stLinkCriteria As String


POTEMP = Me.PO.Value
NuaNumTmp = Me.NUANUm.Value
MsgBox POTEMP
MsgBox NuaNumTmp

stDocName = "SWLicensesform"
DoCmd.OpenForm stDocName, , , , acFormAdd, , stLinkCriteria
Exit_Command39_Click:
Exit Sub
Err_Command39_Click:
MsgBox Err.Description
Resume Exit_Command39_Click

End Sub




On the SwLicenses Form is a button to add a default

Private Sub WinXP_Click()
On Error GoTo Err_WinXP_Click
DoCmd.GoToRecord , , acNewRec
Me.software.Value = "Windows XP"
Me.Publisher.Value = "Microsoft"
Me.VersionTxt.Value = "Professsional"
Me.Quantity.Value = "1"
Me.LicType.Value = "OEM"
Me.Status.Value = "active"
Me.NUANUm.Value = NuaNumTmp
Me.PO.Value = POTEMP
Me.LicenseNumber.SetFocus
MsgBox POTEMP
exit_WinXP_Click:
Exit Sub

Err_WinXP_Click:
MsgBox Err.Description
Resume exit_WinXP_Click
End Sub
 
S

Storrboy

For starters, where are they Dim'd and where else are they used? Are you
sure they are not being re-valued elsewhere between the uses you have
outlined?
 
B

Bmusgrove

I implicitly declared them in the past. I have just finished trying
explicitly declaring them with no result Command39 is the only place they
are set. There are several buttons on the SWLicense form that use the value
to fill in fields.


I made no coding changes at all between my backup (which still works) and
the one that does not work. All that happened is I compacted the database.

I tried setting the modules to break on all errors, with no results.
I used MSGBOX in a event procedure for the get focus and lost focus on
command 39 and with the ON LOAD and ON OPEN for the second form SWLicensesS
Form., and discovered :

Press Command 39 button on main form
Variables are set and viewable using MSGBox
SwLicensesForm OPEN and LOAD, the variable is not present
Commnd39 lost focus, the variables are present
toggle between the open main form and open SWLicensesForm, and the variables
are present when the main form gets focus, and not present in the
SwLicenseForm. I tried it on several other forms, and the variables always
exists when toggling back to the main form, but do not get passed to any
other form.
 
D

Douglas J. Steele

I see no way they could ever have been passed to the SWLicensesform form!

You either need to assign stLinkCriteria (if your intent is to use them to
limit what's shown on the second form), or else pass them as the OpenArgs
argument in the DoCmd.OpenForm method.
 
B

Bruce

It did! I promise :) That is a cut and paste from the database so I did
not type the code in wrong.
Form one is my computer inventory, compsys. Form 2 is my software licenses ,
SWLicencesForm. Whn I press button Command39 on the Compsys form it sets the
POTEMP variable and NuaNumTemp Variable using

POTEMP = Me.PO.Value
NuaNumTmp = Me.NUANUm.Value

and then opens using the comamnd

stDocName = "SWLicensesform"
DoCmd.OpenForm stDocName, , , , acFormAdd, , stLinkCriteria


On the SWLicensesForm, it opens to a new record. I press the button WINXP
and it fills in a several fields for me, and it should fill in the fileds PO
and NuaNum from the variables POTEMP and NuaNumTmp (passed from COMPSYS
form) uisng
Me.NUANUm.Value = NuaNumTmp
Me.PO.Value = POTEMP

But it has just quit working!!!!!!! I can think of no coding changes. I
have added a coupole of valuse to somne static lookup tables used for drop
down compboboxes, and that is it. None of those entries arecalled POTEMP or
NuaNumTMP. It is driving me nuts!!!!!!!
 
B

Bruce

The intent is not to limit what is shown. It is to pass two variables from
form1 to form2, so when I push one of several buttons on form2 it can
automatically populate two of the fields using the variables carried from
form1. Those "several butons" I refer to populate several other fields on
the form with different values, depending on which button I push.

I had not used OpenArgsa on it beore, and it worked. I do not think I can
pass two variable using OpenArgs. I can probably make it work again by
changing
Me.NUANUm.Value = Forms!form1!NuaNum.value
Me.PO.Value = Forms!Form1!.PO.value

But the stubborn part of me wants to understand why it quit working.
 
B

Bruce

BTW, I declared them as a public variable in a module by themselves, and now
it works great. I had not done that before and it worked, but somehow it
"broke".
My curiosity (stubborness ) wants to know why......

What is the best way to get information from one open form to another?
Use Public variables?
Pull it from the other form using Form2.Fieldname=Forms!Form1!fieldname?
Another method?

BY best I am thinking along the lines of best coding practices......
 
R

Rick Brandt

Bruce said:
BTW, I declared them as a public variable in a module by themselves,
and now it works great. I had not done that before and it worked,
but somehow it "broke".
My curiosity (stubborness ) wants to know why......

What is the best way to get information from one open form to another?
Use Public variables?
Pull it from the other form using Form2.Fieldname=Forms!Form1!fieldname?
Another method?

BY best I am thinking along the lines of best coding practices......


You probably were not "passing" the variables before and you are not passing
them now. You have public variables that both forms can "see". If one form
sets the value of those variables then the other form will be able to see those
new values, but that is not "passing" and your post was confusing because it
used that terminology.

If it was ever working without having the variables declared it might be because
you were not using OPTION EXPLICIT. Having that at the top of a module forces
all variables to be explicitly declared (safer). Without it then variables can
be just made up as you go along and they will still work (not so safe).

I have only ever considered OPTION EXPLICIT in the case of module level or
procedure level variable scope. I don't know if NOT using it even applies to
public variables that are scoped across the entire app, but if so that might
explain why this was working for you before. OPTION EXPLICIT was not being used
before and now it is.
 
S

Storrboy

Bruce said:
BTW, I declared them as a public variable in a module by themselves, and now
it works great. I had not done that before and it worked, but somehow it
"broke".
My curiosity (stubborness ) wants to know why......
What is the best way to get information from one open form to another?
Use Public variables?
Pull it from the other form using Form2.Fieldname=Forms!Form1!fieldname?
Another method?

BY best I am thinking along the lines of best coding practices......


My opinion...
....is that application public (global) variables should be limited to
information that will not change or do so rarely - such as a object
references that exist throughout the environment. Data that needs to be
passed between forms, functions or other subs should be done as arguments,
OpenArgs or have the object that needs them get them from the source as the
example you gave above. Having variables floating around with (potentially)
random values means more work in determining if the value is what you need -
for instance, what if the current value of a var in Sub1 is not what Sub2
needs AND Sub1 isn't finished with it? If it changes in Sub2 and control
returns to Sub1, the value is no longer valid and Sub1 could possible give
the wrong results.

I am unsure though as to why it would work one day and not the next, might
be one of those things that only close scrutiny of the project would reveal.
 
B

Bruce

I never have used Option Explicit, in this database, even though I am aware
of it and why it should be used (bad boy). I am working on that as I revise
a lot of little things that I did quick and dirty to get it up and running
several years ago. As it was for my use only, and it was also learning tool
(being my first foray into a more complicated relational database), I was
not worried about being programmatically correct :( That is not an excuse ,
but I have slowly learned better

My verbage may be incorrect as far as using the word "passing". For that I
apologize. When you do this on the side for yourself and your department
instead of as a living, you don't always use the correct term. By passing I
was referring to FORM1 opening Form2, and form2 being able to use 2
variables that were created when the command button (in form1) to open Form2
was pressed. If I remember correctly I used a variable so if form 1 was
open and I added material to form2, the variables would be available to
form2. Form1 was not opened, and FORM2 was used to add items,then the
variable would not be available and the corresponding fields on form2 would
be blank and have to be manually filled in.

As I look back at it, I can't see how it was able to work before unless
there was a "bug" that was closed with a recent MSOffice 2002 patch.
 

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