Dimension Help (1 Viewer)

Ripley

Registered User.
Local time
Today, 20:21
Joined
Aug 4, 2006
Messages
148
Hi.

I need help declaring a dimension based upon a selection statement:

Code:
If selection = "D" Then
Dim testpayto as Form_frmCustomers
Else
If selection = "F" then
dim testpayto as Form_frmCustomers[2]
End If
End If

I get an error message saying that that the variable "testpayto" has been declared already, but clearly it cannot have been becuase the selection only dimensions based upon the "selection" value.

Can anybody help?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:21
Joined
Feb 28, 2001
Messages
27,328
Don't do it your way. Look at this and see if it works for you.

Code:
Dim TestPayTo as Form

...

Select [Selection]
  Case "D"
    Set TestPayTo = Forms("Form_frmCustomers")
  Case "F"
    Set TestPayTo = Forms("Form_frmCustomers[2]")
  Case Else
   {put error trapping code here}
End Select

TestPayTo.OpenForm etc.etc.etc.

In order for it to work this way, you MUST have the form open already.

If neither form would be open already, you might instead want to try to open it from the Documents collection ... CurrentDB.Documents("form1") is the syntax you want if I remember correctly. Forms that aren't open yet aren't in the Forms collection. But they ARE in the documents collection.

By the way, don't take this as an attempt to be abrasive, but GET RID OF ANY FORM DECLARED WITH A (number). Rename it. You are asking for serious trouble.

What's in a name? Not much - a form by any other name would be as sweet - or as clunky - as it always was, but the FORMS collection won't be so confusing if you scan it programmatically.
 

Users who are viewing this thread

Top Bottom