Compile error: Invalid use of property

harob

New member
Local time
, 21:18
Joined
Aug 25, 2010
Messages
2
Hello,
I am creating a start screen for a database an I get the following error: Compile error: Invalid use of property

My code is following:

Option Compare Database
Option Explicit

Private Sub cmdNext_Click()
DoCmd.Close acForm, "frmStart", acSaveYes
End Sub

Private Sub Form_Load()
Dim frm As Form

'The standard menu bar is shown
MenuBar False

Set frm = Form_frmStart
If frm.StartScreen = False Then
DoCmd.Close acForm, "frmStart"
End If
Set frm = Nothing
End Sub

What is wrong?
Thanks.
 
You are using MenuBar wrong. What is your intention with it? The syntax in VBA Help shows:

Me.MenuBar = "SomeMenuBarName"

or to not use it

Me.MenuBar = ""
 
You have 2 things you need to comment out.

End Sub

Private Sub Form_Load()

Near the beginning of your code you have the End sub comment that out or delete it. Then just below you have the Private Sub to the same here.

If you want a form to start when the database is opened, you can create a MACRO to open the form and any other actions, then save the MACRO as AutoExec

This will open the form when the database opens as it is an executable command in the database.

It would be useful to state what version of MS Office is being used as well, as the menu bar won't work in Access 2007.
 
You have 2 things you need to comment out.



Near the beginning of your code you have the End sub comment that out or delete it. Then just below you have the Private Sub to the same here.
No, Trevor - it is shown correctly. There are two subs shown here.
 
Hi Bob,

The original quote which I read stated I am creating a Start Screen, so the cmd button would be on the form, not when it opened, but I do see your point as the Private Sub Form Load is indicated.

I suppose the only code that needed to be added to the thread was the form event.
 
But Harob -

I would change this part:

Code:
Private Sub cmdNext_Click()
DoCmd.Close acForm, "frmStart", acSaveYes
End Sub

to this:
Code:
Private Sub cmdNext_Click()
DoCmd.Close acForm, "frmStart", [B][COLOR=red]acSaveNo[/COLOR][/B]
End Sub

acSaveYes doesn't mean save the record. It means save DESIGN CHANGES to the form. acSaveNo prevents design changes being saved to your form (which could include persistent filters, etc.).

If you want to save a record explicitly you would use either:
Code:
If Me.Dirty Then Me.Dirty = False

or
Code:
DoCmd.RunCommand acCmdSaveRecord

And the difference is, that the first one will only attempt a save if something has changed where the seoncd will attempt a save regardless.
 
Hi Bob,

The original quote which I read stated I am creating a Start Screen,
They said they were creating a Start Screen (splash form) and that they were getting a COMPILE ERROR and so there is nothing off from their code there EXCEPT the part in red about the menubar. That was my point. There is nothing wrong with the load event per se or anything else, but the use of the MenuBar code (which since it was in red was what I assumed they were talking about that was producing the error) and which is incorrect usage.

So, anyway, you read it one way and I read it another but I was concerned because you said that they had an extra End Sub which is not true.
 
They said they were creating a Start Screen (splash form) and that they were getting a COMPILE ERROR and so there is nothing off from their code there EXCEPT the part in red about the menubar. That was my point. There is nothing wrong with the load event per se or anything else, but the use of the MenuBar code (which since it was in red was what I assumed they were talking about that was producing the error) and which is incorrect usage.

So, anyway, you read it one way and I read it another but I was concerned because you said that they had an extra End Sub which is not true.

Hello,
yes it was right that I used MenuBar wrong and I use Access 2007.I just started with access and have to translate an existing database. Is there an overview of the words I cannot use?

I corrected the error, but now I get the following error:

Run-time error '2094':
Microsoft cannot find the toolbar 'Options'

Public Sub TaskBar(ReportBar As Boolean)
If ReportBar = True Then
DoCmd.ShowToolbar "Report", acToolbarYes
DoCmd.ShowToolbar "Options", acToolbarNo
Else
DoCmd.ShowToolbar "Options", acToolbarYes
DoCmd.ShowToolbar "Report", acToolbarNo
DoCmd.ShowToolbar "Export", acToolbarNo
End If

End Sub

Thanks
 

Users who are viewing this thread

Back
Top Bottom