Parm reference in called subroutine

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

Guest

The code below opens the correct form, the msgbox shows the correct string
(Order Tee Shirts), but I get an error msg on the next line that :

Microsoft Access can’t find the form ‘strToForm' referred to….

How do I get the value for the string to be substituted correctly into the
assignment statement?


Call OpenNewForm("Order Tee Shirts", "Team Entries")
…
…
Public Sub OpenNewForm(strToForm As String, strFromForm As String)

DoCmd.OpenForm strToForm
MsgBox (strToForm)
[Forms]![strToForm]![Full Name] = [Forms]![Team Entries]![Full Name]

End Sub
 
Steve said:
The code below opens the correct form, the msgbox shows the correct
string (Order Tee Shirts), but I get an error msg on the next line
that :

Microsoft Access can't find the form 'strToForm' referred to..

How do I get the value for the string to be substituted correctly
into the assignment statement?


Call OpenNewForm("Order Tee Shirts", "Team Entries")
.
.
Public Sub OpenNewForm(strToForm As String, strFromForm As String)

DoCmd.OpenForm strToForm
MsgBox (strToForm)
[Forms]![strToForm]![Full Name] = [Forms]![Team Entries]![Full
Name]

End Sub

Instead of the syntax...

[Forms]![strToForm]![Full Name]

....use...

Forms(strToForm)![Full Name]
 
thanks. That worked but I sure do not know why. I had tried several
versions trying to make it work with & and " with no success. I would never
have tried what you suggested. Can you explain what adn why?

thanks again

steve

Rick Brandt said:
Steve said:
The code below opens the correct form, the msgbox shows the correct
string (Order Tee Shirts), but I get an error msg on the next line
that :

Microsoft Access can't find the form 'strToForm' referred to..

How do I get the value for the string to be substituted correctly
into the assignment statement?


Call OpenNewForm("Order Tee Shirts", "Team Entries")
.
.
Public Sub OpenNewForm(strToForm As String, strFromForm As String)

DoCmd.OpenForm strToForm
MsgBox (strToForm)
[Forms]![strToForm]![Full Name] = [Forms]![Team Entries]![Full
Name]

End Sub

Instead of the syntax...

[Forms]![strToForm]![Full Name]

....use...

Forms(strToForm)![Full Name]
 
Steve S said:
thanks. That worked but I sure do not know why. I had tried several
versions trying to make it work with & and " with no success. I would never
have tried what you suggested. Can you explain what adn why?

There are numerous ways to reference things and specifically so that one can use
a variable name Access provides one that takes a string. The following all work
the same...

Forms!FormName!ControlName
Forms("FormName")!ControlName
Forms!FormName("ControlName")
Forms("FormName")("ControlName")
 

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