CreateControl method compile error (1 Viewer)

rede96

Registered User.
Local time
Today, 18:08
Joined
Apr 2, 2004
Messages
134
I am using Access 2003 and I am trying to use the createcontrol method (See Code below).

I just copied some example code from Microsoft, however I keep getting a complie error when compiling the code.

The error says: "Expected variable or procedure, not project" and the createcontrol method is highlighted.

Can anyone help please?

Code:
Private Sub Command0_Click()

    Dim frm As Form
    Dim ctlLabel As Control, ctlText As Control
    Dim intDataX As Integer, intDataY As Integer
    Dim intLabelX As Integer, intLabelY As Integer
    
    ' Create new form with Orders table as its record source.
    Set frm = CreateForm
    frm.RecordSource = "Orders"
    ' Set positioning values for new controls.
    intLabelX = 100
    intLabelY = 100
    intDataX = 1000
    intDataY = 100
    ' Create unbound default-size text box in detail section.
    Set ctlText = createcontrol(frm.Name, acTextBox, , "", "", _
        intDataX, intDataY)
    ' Create child label control for text box.
    Set ctlLabel = createcontrol(frm.Name, acLabel, , _
         ctlText.Name, "NewLabel", intLabelX, intLabelY)
    ' Restore form.
    DoCmd.Restore
End Sub
 

missinglinq

AWF VIP
Local time
Today, 13:08
Joined
Jun 20, 2003
Messages
6,420
Of course, Access error messages are noted for not actually pointing to the real problem! The first thing that comes to mind is to ask whether you have a table named "Orders" since you're trying to set this as the RecordSource for the form you're creating.

Also, since I see you've got this code set in a control's OnClick event, did you notice in the Help file you copied the code from that this can only be done in Design View?

Linq
 

unclejoe

Registered User.
Local time
Tomorrow, 01:08
Joined
Dec 27, 2004
Messages
190
You got it wrong by puting the code into the button event. You must put this code into a standard module. Than, call it from your button event.

I am using Access 2003 and I am trying to use the createcontrol method (See Code below).

I just copied some example code from Microsoft, however I keep getting a complie error when compiling the code.

The error says: "Expected variable or procedure, not project" and the createcontrol method is highlighted.

Can anyone help please?

Code:
Private Sub Command0_Click()

    Dim frm As Form
    Dim ctlLabel As Control, ctlText As Control
    Dim intDataX As Integer, intDataY As Integer
    Dim intLabelX As Integer, intLabelY As Integer
    
    ' Create new form with Orders table as its record source.
    Set frm = CreateForm
    frm.RecordSource = "Orders"
    ' Set positioning values for new controls.
    intLabelX = 100
    intLabelY = 100
    intDataX = 1000
    intDataY = 100
    ' Create unbound default-size text box in detail section.
    Set ctlText = createcontrol(frm.Name, acTextBox, , "", "", _
        intDataX, intDataY)
    ' Create child label control for text box.
    Set ctlLabel = createcontrol(frm.Name, acLabel, , _
         ctlText.Name, "NewLabel", intLabelX, intLabelY)
    ' Restore form.
    DoCmd.Restore
End Sub
 

rede96

Registered User.
Local time
Today, 18:08
Joined
Apr 2, 2004
Messages
134
Hi and thanks for the replies,

I see you've got this code set in a control's OnClick event

It was in the onClick event of a different form than the one I am trying to create a new control. So this shouldn't be an issue.

whether you have a table named "Orders"

I do have a table called orders, however wouldn't the code still compile and the code just break when it got the line referencing the missing table?

You must put this code into a standard module

I did already try that but still get the compile error.


Another think I noticed, when typing code in an Access module for example, when you type in the name of a recognised method such as DoCmd, Access VBA shows it recognises the name of the method by changing the appropriate letters in the name to capitals.

For example "docmd.restore" would become "DoCmd.Restore"

It doesn't do this with the createcontrol method. It's like it just doesn't recognise this method.

Also, I tried the code on another PC using Access 2002 and the code compiles no problem.
 

RoyVidar

Registered User.
Local time
Today, 19:08
Joined
Sep 25, 2000
Messages
805
Rename the database to something other than createcontrol.
 

rede96

Registered User.
Local time
Today, 18:08
Joined
Apr 2, 2004
Messages
134
Rename the database to something other than createcontrol.

Doh! :eek: :eek: :eek:

Actually, to save some of my blushes, I did already try and rename the database from createcontrol to other names but it didn't work.

However after reading your post I created a new database with a different name and that worked. :)

bl**dy databases!

Thank you

Red.
 

RoyVidar

Registered User.
Local time
Today, 19:08
Joined
Sep 25, 2000
Messages
805
Ah, yes, sorry, actually, it should be enough to enter Tools | TheProject Properties... in the VBE, then change the project name there.
 

Users who are viewing this thread

Top Bottom