Problem with Data Types

  • Thread starter Thread starter cinnie
  • Start date Start date
C

cinnie

hi to all
I am writing a function whose parameters are the form that is active when
the function is called (frmFROM), and the form that the function then opens
(frmTO).

My problem is that the frmTO is used as a string in line 5 and 8, but as a
form in line 6. Whichever way I Dim frmTO, I get a crash. How can reslove
this problem?

1 Function ReturnToMenu(frmFROM As Form, frmTO As String)

2 frmFROM.Visible = False
3 Dim prj As Object
4 Set prj = Application.CurrentProject

5 If prj.AllForms(frmTO).IsLoaded Then
6 Forms!frmTO.Visible = True
7 Else
8 DoCmd.OpenForm frmTO
9 End If
10 .....

much thanks
 
If frmTo is open in its own right (i.e. not as a subform), you can refer to
it using the string name like this:
Forms(frmTo)

But it would be better to pass in a reference to the form itself (ie As
Form, not As String) so it works with subforms and sub-subforms.
 
thanks Allen for your reply

I can see why it it better to pass in a reference to the form itself, as you
have advised (... frmTO As Form), but I'm struggling with the proper syntax.
Would you be able to tell me how the following code snippet would look if
a) I passed the reference as (... frmTO As Form) , then if
b) I passed the reference as (... frmTO As String)

thanks for your expertise
 
That should work if you change line 6 to:
Forms(frmTO).Visible = True
 

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