Assigning Public Variables To Controls

  • Thread starter Thread starter nouveauricheinvestments
  • Start date Start date
N

nouveauricheinvestments

I am getting really really frustrated about this. I haven't the
slightest idea what is wrong. I have a form that I have assigned
about seven different controls to 7 different public variables, as
listed below. What happens is a form is filled out, the user hits
submit, and a group of the controls are assigned to public variables.
The user then is presented with another form where he needs to fill
out some more data and hit submit. When he submits that form, a new
form is brought up. This new form has the following code in the
Form_Load event procedure. It does not work though. When it tries to
bring up the form, it asks me the following: Forms!PrintableVersion!
Explanation. It wants to know what that value should be. It is
listed below, right in the form_load code. What do you think is
wrong? when I go to the immediate window and type Msgbox Exp, It
gives me what Exp is, so I can't understand why it doesn't just assign
that value to the control...



Me!DAT = DT
Me!FName = FNm
Me!LName = LNm
Me!Account = Acc
Me!Server = Serv
Me!Email = Em
Me!Explanation = Exp
Me!DesResolution = Res
Me!Rep = Rp
 
I am getting really really frustrated about this. I haven't the
slightest idea what is wrong. I have a form that I have assigned
about seven different controls to 7 different public variables, as
listed below. What happens is a form is filled out, the user hits
submit, and a group of the controls are assigned to public variables.
The user then is presented with another form where he needs to fill
out some more data and hit submit. When he submits that form, a new
form is brought up. This new form has the following code in the
Form_Load event procedure. It does not work though. When it tries to
bring up the form, it asks me the following: Forms!PrintableVersion!
Explanation. It wants to know what that value should be. It is
listed below, right in the form_load code. What do you think is
wrong? when I go to the immediate window and type Msgbox Exp, It
gives me what Exp is, so I can't understand why it doesn't just assign
that value to the control...



Me!DAT = DT
Me!FName = FNm
Me!LName = LNm
Me!Account = Acc
Me!Server = Serv
Me!Email = Em
Me!Explanation = Exp
Me!DesResolution = Res
Me!Rep = Rp


Nothing there refers to anything called Forms!PrintableVersion!Explanation.
Is that expression used as, perhaps, a controlsource or default value for a
control on the form? Or maybe in the form's recordsource?

If that's not the problem, please show all the code in the Form_Load
procedure; maybe that will help us spot the error.
 
Nothing there refers to anything called Forms!PrintableVersion!Explanation.
Is that expression used as, perhaps, a controlsource or default value for a
control on the form? Or maybe in the form's recordsource?

If that's not the problem, please show all the code in the Form_Load
procedure; maybe that will help us spot the error.

This code is in the Form_Load Procedure. The me!Explanation refers to
the same as Forms!PrintableVersion!Explanation, as the form_load
procedure is for the printableversion form. I'm way past this though,
sorry. I found a workaround. If anyone is interested, I have
explained below.

I opened the form with the following line when I complete the first
form:

DoCmd.OpenForm "PrintableVersion"
Form_PrintableVersion.DAT = Me!DAT
Form_PrintableVersion.Account = Me!Account
Form_PrintableVersion.FName = Me!FName
Form_PrintableVersion.LName = Me!LName
Form_PrintableVersion.Explanation = Me!Explanation
Form_PrintableVersion.DesResolution = Me!
DesResolution
Form_PrintableVersion.Rep = Me!Rep
Form_PrintableVersion.Server = Me!Server.Column(1)
Form_PrintableVersion.Email = Me!Email
Form_PrintableVersion.Visible = False

DoCmd.OpenForm "OrderDetails"
Form_OrderDetails.TrueFalse = Me!Explanation
Form_OrderDetails.DAT = Me!DAT
DoCmd.Close acForm, Me.Name

When OrderDetails is submitted, the following code is run:

Form_PrintableVersion.PrintableVersionOrderDetailsQuery_subform.Requery
Form_PrintableVersion.Visible = True
DoCmd.OutputTo acOutputForm, "PrintableVersion", acFormatPDF, MyPDF,
False, , , acExportQualityScreen


A little messy, but it works good enough.
 
This code is in the Form_Load Procedure. The me!Explanation refers to
the same as Forms!PrintableVersion!Explanation, as the form_load
procedure is for the printableversion form. I'm way past this though,
sorry. I found a workaround. If anyone is interested, I have
explained below.

I opened the form with the following line when I complete the first
form:

DoCmd.OpenForm "PrintableVersion"
Form_PrintableVersion.DAT = Me!DAT
Form_PrintableVersion.Account = Me!Account
Form_PrintableVersion.FName = Me!FName
Form_PrintableVersion.LName = Me!LName
Form_PrintableVersion.Explanation = Me!Explanation
Form_PrintableVersion.DesResolution = Me!
DesResolution
Form_PrintableVersion.Rep = Me!Rep
Form_PrintableVersion.Server = Me!Server.Column(1)
Form_PrintableVersion.Email = Me!Email
Form_PrintableVersion.Visible = False

DoCmd.OpenForm "OrderDetails"
Form_OrderDetails.TrueFalse = Me!Explanation
Form_OrderDetails.DAT = Me!DAT
DoCmd.Close acForm, Me.Name

When OrderDetails is submitted, the following code is run:

Form_PrintableVersion.PrintableVersionOrderDetailsQuery_subform.Requery
Form_PrintableVersion.Visible = True
DoCmd.OutputTo acOutputForm, "PrintableVersion", acFormatPDF, MyPDF,
False, , , acExportQualityScreen


A little messy, but it works good enough.


Congratulations on solving your own problem. Let me give you a word of
caution, though: although it does work, I strongly suggest that you not use
the FormFormName style of reference. Instead, use Forms!FormName or
Forms("FormName"). The explanation of why you shouldn't do that (unless you
really know what you're doing) is a bit complicated, but the two reference
forms are *not* equivalent.

Form_FormName is a reference to the class module of a form. If the form
does not have a class module (because it has no VBA code behind it), that
reference will fail. Further, if the form does have a class module, but is
not open when you make the reference, it will be automatically opened,
silently, but hidden so the user doesn't see it -- and its name will not be
added as an index to the Forms collection, so future references by name,
such as Forms!FormName or Forms("FormName") will fail.

Your code above would be better rewritten as:

'----- start of suggested revision -----
DoCmd.OpenForm "PrintableVersion", WindowMode:=acHidden
With Forms!PrintableVersion
!DAT = Me!DAT
!Account = Me!Account
!FName = Me!FName
!LName = Me!LName
!Explanation = Me!Explanation
!DesResolution = Me!DesResolution
!Rep = Me!Rep
!Server = Me!Server.Column(1)
!Email = Me!Email
End With

DoCmd.OpenForm "OrderDetails"

With Forms!OrderDetails
!TrueFalse = Me!Explanation
!DAT = Me!DAT
End With

DoCmd.Close acForm, Me.Name

' ...
' ... When OrderDetails is submitted, the following code is run:
' ...

With Forms!PrintableVersion
!PrintableVersionOrderDetailsQuery_subform.Requery
.Visible = True
End With

DoCmd.OutputTo acOutputForm, "PrintableVersion", _
acFormatPDF, MyPDF, False, , , acExportQualityScreen

'----- end of suggested revision -----
 
Congratulations on solving your own problem. Let me give you a word of
caution, though: although it does work, I strongly suggest that you not use
the FormFormName style of reference. Instead, use Forms!FormName or
Forms("FormName"). The explanation of why you shouldn't do that (unless you
really know what you're doing) is a bit complicated, but the two reference
forms are *not* equivalent.

Form_FormName is a reference to the class module of a form. If the form
does not have a class module (because it has no VBA code behind it), that
reference will fail. Further, if the form does have a class module, but is
not open when you make the reference, it will be automatically opened,
silently, but hidden so the user doesn't see it -- and its name will not be
added as an index to the Forms collection, so future references by name,
such as Forms!FormName or Forms("FormName") will fail.

Your code above would be better rewritten as:

'----- start of suggested revision -----
DoCmd.OpenForm "PrintableVersion", WindowMode:=acHidden
With Forms!PrintableVersion
!DAT = Me!DAT
!Account = Me!Account
!FName = Me!FName
!LName = Me!LName
!Explanation = Me!Explanation
!DesResolution = Me!DesResolution
!Rep = Me!Rep
!Server = Me!Server.Column(1)
!Email = Me!Email
End With

DoCmd.OpenForm "OrderDetails"

With Forms!OrderDetails
!TrueFalse = Me!Explanation
!DAT = Me!DAT
End With

DoCmd.Close acForm, Me.Name

' ...
' ... When OrderDetails is submitted, the following code is run:
' ...

With Forms!PrintableVersion
!PrintableVersionOrderDetailsQuery_subform.Requery
.Visible = True
End With

DoCmd.OutputTo acOutputForm, "PrintableVersion", _
acFormatPDF, MyPDF, False, , , acExportQualityScreen

'----- end of suggested revision -----

Oh wow. That is a BIG deal Dirk. Thank you for filling me in on
that. I did notice that I could not reference the form if there was
no corresponding class module but I did not realize the negative
affect of referring to the form by it's module. I will go through and
recode everything so that all Form_FormName references are changed to
Forms!FormName.

Thanks Dirk. I really appreciate that.
 
Back
Top