Can someone help me write a really simple code?

CarlyS

Registered User.
Local time
Today, 03:50
Joined
Oct 9, 2004
Messages
115
I do not know anything about writing code, but code builder sometimes helps. I am trying to follow what it suggests, but it keeps telling me it is expecting an = somewhere. I used ghudson's code to hide all toolbars and I want to add a custom toolbar to my report previews. The custom toolbar is called "Print Report". Here is the code that isn't working to show this custom toolbar. Can anyone fix it for me?

Private Sub Report_Open(Cancel As Integer)
DoCmd.ShowToolbar(Print_Report, [Show As AcShowToolbar = acToolbarYes])
End Sub

Extremely grateful for any help at all,
Carly
 
Use the following :

Code:
DoCmd.ShowToolbar "Print_Report", acToolbarYes

When using the code editor start to type in the command and when the controltip shows, includes commas where applicable and aprt from the variables that need to be defined, the rest of the code will appear automatically. Try typing in the above code and think about what controltips appear.

This should give you an idea of how it works.

Hope this Helps

Andy
 
No error message, but no toolbar either...

Thank you so much Andy. The code you gave me does not produce the error message anymore, but by toolbar is nowhere to be seen either...

Any ideas as to why?

When I try to follow the suggestions of the code editor, it prompts me for an =. I guess I am still not getting it.
 
Firstly where are you putting the code. You may need to set the report properties toolbar property to Print report has opposed to using code.

Post where you are putting the code and on what event.

The showtoolbar = actoolbaryes is just to show that the actoolbaryes is the property to show the toolbar.

Generally the = in code happen in the following circumstances:

  1. Setting a forms visible property to true/false
    Code:
    me.form.visible = true

  2. Setting a control to a particular value
    Code:
    me.textbox = me.othertextbox

Hope this helps

Andy
 
I was putting the code in the Open event for a report. I want there to be no toolbars generally. Then, when someone opens a report, the "Print Report" toolbar will show (so they can print it and close the preview page). I also plan to hide the toolbar in the Close event of the report, but I was thinking that would be easy one I figured out how to show the toolbar.
This is what I was using that gave no error message but failed to show the toolbar:

Private Sub Report_Open(Cancel As Integer)
DoCmd.ShowToolbar "Print_Report", acToolbarYes
End Sub


What do you think?
 
Carly,

I haven't played with toolbars for a while, so bear with me.

Check that the hide all toolbars code is not cancelling out the open event.
Where do you have this code?

Have you set the toolbar property to Menu Bar/toolbar and not popup.
If it's set to popup it will only show on right click menu.

Also check the report's properties to make sure the Toolbar and Shortcut properties do not have other values.

The code is recognising the toolbar is there, but there must be something hiding the toolbar or it's set to popup.

Let me know what happens.

Andy
 
I have this code (posted by ghudson) in my main menu form's on open event:

Private Sub Form_Open(Cancel As Integer)
Dim i As Integer
For i = 1 To CommandBars.Count
CommandBars(i).Enabled = False
Next i
End Sub

I then came across this posting which implied that this code should allow you to unhide a specific toolbar when necessary using the DoCmd.ShowToolbar command. Here is the posting:

ghudson
Dazed & Confused Join Date: Jun 2002
Location: USA
Posts: 2,427
I have posted that code all over this forum. You only need to run it once [opening splash form or main menu] to hide all the tool bars and menu bars for that application. Then use the DoCmd.ShowToolbar command for a specific tool bar when needed.

I checked that the report properties for modal and popup are set to no, and that nothing is in the Toolbar, or Menu or Shortcut properties.

Thank you so much for bearing with me!!!
 
Carly,

Any chance of a quick sample db? maybe we are missing something.

Have you tried right clicking the report to see if a menu appears?

Follow the menu path :

Tools > Customise > Select the toolbar name and click on properties.
What type does is say? is it Menu Bar/Toolbar or Popup

Andy
 
Last edited:
I believe ghudson's code is also supposed to disallow right clicking menu as well, which is also quite nice. So, right clicking does nothing (but rightfully so). Ok, here is the database. Thank you so much for taking the time.
 

Attachments

Hi Carly,

Found the problem. Code is absolutely fine.
There is no toolbar called Print Report or Print_Report.

If you changed the toolbarname to print preview so the code looks like :
Code:
Docmd.ShowToolbar "Print preview",actoolbaryes
The Access Print preview toolbar appears.
The toolbar you created does not exist in the db.
If you use the Menu path :

Tools > Customise and create a toolbar.

If you get stuck, let me know and I will change your sample to show this.
You are on the right track.


Hope this Helps
Andy
 
Toolbars are being dropped from the list it seems

Ok, I see what you are saying, but I did have that toolbar and now it is gone. I tried creating another one and putting the name of the new one in the code and that is now missing from the list as well. I finally just tried editing the print preview toolbar and that is now missing from the list. Any idea why this could be?
 
Now almost all the toolbars left town...

I now only have two on the list:
Menu Bar
Shortcut menus

How do I restore to system defaults?

This must be a setting I selected for all of Access because it happens in my backup databases as well.
 
Ok, I got it to restore the original ones and I am now simply back to the problem of the toolbar disappearing after the show toolbar code is run. Why would toolbars ever disappear from the list?
 
Carly,

Have you fixed it yet?
Follow ghudson's comments and you won't go far wrong.

Andy
 
Thank you so much for checking up on me and bearing with me. Yes, it works!
I did, however, like the way ghudson's original code disallowed the right click menu. If you know another trick to that, please let me know!

Thank you so much for all your help and patience!
 
You can control that property at the form level with code.
Code:
Private Sub Form_Open(Cancel As Integer)
    
    Me.ShortcutMenu = False
    
End Sub
You can also do it with a StartUp command but the above will give you more control for you could test it with an IF statement and turn the ShortcutMenu property on or off for a specific form based on who the user is.
 
CarlyS said:
Thank you so much for checking up on me and bearing with me. Yes, it works!
I did, however, like the way ghudson's original code disallowed the right click menu. If you know another trick to that, please let me know!

Thank you so much for all your help and patience!
No Problem. Glad you sorted it. I can remember when I had these problems but as time goes on it gets easy, that's the learning curve.

Good Luck in your project.

Andy
 

Users who are viewing this thread

Back
Top Bottom