PDA

View Full Version : Solved: How come this works on 2007 but not on 2003



Djblois
03-19-2007, 09:25 AM
Dim FirstUserForm as UserForm

set FirstUserForm = SalesReport
FirstUserForm.Show

SalesReport is the name of the form

lucas
03-19-2007, 09:45 AM
I'm not sure daniel but why would you want to use that much code to get

salesreport.show

Djblois
03-19-2007, 09:55 AM
Because I am using it the FirstUserForm.show in a seperate sub that must control different forms depending on which sub called it.

lucas
03-19-2007, 10:01 AM
I'm just confused because you set it....
Set FirstUserForm = SalesReport
Couldn't you use if statements to call the correct form from your various subs?

Djblois
03-19-2007, 10:10 AM
how do you mean lucas? maybe I can

Djblois
03-19-2007, 10:36 AM
This code is supposed to work right?



Dim FirstUserForm As UserForm

Set FirstUserForm = SalesReport
FirstUserForm.Show

austenr
03-19-2007, 10:56 AM
A lot of stuff doesn't seem to work in 2003 if you develope it in 2007. There is supposed to be a service pack in late fall to address a lot of the bugs. Not sure if this is one of them or not. Just got a new computer and it shipped with Vista. I hate Vista. I ordered it with 1GB of ram only to find out that the OS takes up 3/4 of that on boot up. I sincerely wish I had bought a Mac. But alas, that would require buying too much software.

Djblois
03-19-2007, 11:29 AM
Yes but I didn't develop it on 2007. I just tested it at home on 2007 and then retyped it at work on 2003. So, I am wondering if my code is correct. Maybe I typed something different at home, I don't think I did but I have been wrong before.

Ken Puls
03-19-2007, 01:55 PM
Near as I can tell in 2003, the userform does not seem to represent as such, and can be captured by the following:

Dim FirstUserForm As Variant Or...
Dim FirstUserForm As Object Or even...
Dim FirstUserForm As SalesReport
Set FirstUserForm = SalesReport
FirstUserForm.Show

I'd go with Object myself if I were trying to assign it to a variable.

Djblois
03-19-2007, 02:05 PM
Thank you Ken that works perfectly

Ken Puls
03-19-2007, 02:17 PM
You're welcome. As a matter of elegance, I'd agree that it should be typed as Userform. I'm guessing that was fixed in 2007.

For reference, here's some sleuthing tips for future:

I started by taking a stroll through the Object Browser, to see what came up when I gave it the term "show". Scroll down till you find the show (only) method. Nothing related to userforms that I could see came up in 2003.

If you are trying to get the type correct, my next step would be to set it as a variant temporarily. Run the code, then check the locals window to see what has been assigned. In the pic below, it decided on object, although usually, it will tell you what kind.

JonPeltier
03-20-2007, 03:41 PM
As a matter of elegance, I'd agree that it should be typed as Userform.

Not exactly. A userform is a class module, right. To create an instance of any class (i.e., an object), you first declare a variable of the type named by the class. Hence, for a form named FMyForm:


Dim frmMyForm As FMyForm
Set frmMyForm = New FMyForm
With frmMyForm
' etc.
End With


In the immediate window, frmMyForm is listed in the left column, and FMyForm/FMyForm is listed in the right.

Ken Puls
03-20-2007, 04:30 PM
A userform is a class module, right.

:doh Stuck in the trees on that one! I keep forgetting that little detail, but you're right, of course.