Why doesn't this work? (1 Viewer)

gblack

Registered User.
Local time
Today, 20:24
Joined
Sep 18, 2002
Messages
632
Code:
Public gintSEARCH_CRITERIA As String

Sub Button6_Click()

    Load frmCommunity
    gintSEARCH_CRITERIA = “COMMUNITY”
    frmCommunity.Show

End Sub
Whenever I click on button6 I expect two things to happen:
1) my global variable gets set to "COMMUNITY"
2) the frmCommunity opens

As it stands the form opens just fine, but my global variable never gets set to "COMMUNITY", what's going on here?

Respectfully,
-Gary
 

pr2-eugin

Super Moderator
Local time
Today, 20:24
Joined
Nov 30, 2011
Messages
8,494
Should it not be..
Code:
Sub Button6_Click()
    gintSEARCH_CRITERIA = "COMMUNITY"
    DoCmd.OpenForm "frmCommunity"
End Sub
Or am I missing something?
 

gblack

Registered User.
Local time
Today, 20:24
Joined
Sep 18, 2002
Messages
632
I tried that, but it didn't work... it said "Object required"

This worked though:

Code:
Public gintSEARCH_CRITERIA As String

Sub Button6_Click()
    gintSEARCH_CRITERIA = "COMMUNITY"
    Load frmCommunity
    frmCommunity.Show
End Sub

Thanks for the response, it made me think about when I need to set the variable.
 

pr2-eugin

Super Moderator
Local time
Today, 20:24
Joined
Nov 30, 2011
Messages
8,494
Normally you use DoCmd.OpenForm to open the Form. I have not used Load method before. Is it possible you could explain what is that you are doing so I can learn?
 

gblack

Registered User.
Local time
Today, 20:24
Joined
Sep 18, 2002
Messages
632
I use docmd.open form... when I code in MS Access... but it doesn't seem to work with Excel... or maybe I don't have some reference loaded... IDK...

FYI: I've coded many years in VBA in MS Access, but I have only been coding in excel for a very short time... When I looked up how to open forms in Excel, that's the code I found. It worked, so i didn't worry about why, I just used it.

Maybe someone smarter in both venues can tell us why.

Regards,
Gary
 

MarkK

bit cruncher
Local time
Today, 12:24
Joined
Mar 17, 2004
Messages
8,179
A UserForm is a Class module provided by VBA. In the VBA IDE in Excel, if you right click on the Project Explorer window and hover your mouse over Insert, you can add a UserForm to your Excel VBA Project. Whan you add a UserForm object, it shows up in the object browser as a Private Class in the VBA Project referenced by your Excel file. A VBA.UserForm is a lot like an Access.Form, but a UserForm can't be bound to data and doesn't have a RecordSource property.

Access is actually a weird amalgam of object models. Access itself only really provides Form and Report objects, and the controls you can put on them. The Database is provided by Jet, and usually people use DAO to read and write to and from Jet tables, but it's DAO that provides the TabelDef, QueryDef, and Recordset objects we're familliar with. And CurrentDb is Access exposing a DAO.Database. File dialogs are from the Office object model. And all programming modules are provided by VBA.

When you look at the navigation pane and see all your tables and queries, forms and reports, it's actually amazing the diverse programming chunks that make that possible, and make it look like one product.

But yeah, UserForm is VBA. DoCmd and Form are Access.
 

pr2-eugin

Super Moderator
Local time
Today, 20:24
Joined
Nov 30, 2011
Messages
8,494
Thanks Mark, until your reply came through. I did not notice this thread was in the Excel section. Well I have learnt something today ! Makes more sense now ! :)
 

Users who are viewing this thread

Top Bottom