Command Button Open Form

BlueChicken

Usually Confused
Local time
Today, 02:44
Joined
Jun 19, 2009
Messages
88
Code:
Hi!  I have 3 command buttons on one form each to open different forms themselves...  but I cannot for the life of me get my VB code for them working.

The command buttons are:
BookedAirTravelCMD
BookedHotelsCMD
BookedCarRentalsCMD

The forms I want opened are:
BookedEmployeeAirlineTickets
BookedEmployeeHotels
BookedEmployeeRentalCars

I have loaded all of my forms into VB using the "Build Event..." "Choose Builder" and have tried using this code:

[code]Private Sub BookedAirTravelCMD_Click()
BookedEmployeeAirlineTickets.show
End Sub

Private Sub BookedHotelsCMD_Click()
BookedEmployeeHotels.show
End Sub

Private Sub BookedCarRentalsCMD_Click()
BookedEmployeeRentalCars.show
End Sub
However it doesn't work, and ends up giving me the error "424" Object Required.

Can someone help?:confused:[/CODE]

Problem solved! :D
 
Last edited:
Try the button wizard. It will use

DoCmd.OpenForm ...
 
Holy cow - that was easy... :D I had turned off the wizard before so I could do some other things... jezz lol... THANKS!
 
Using the Wizards, as Paul suggested, is the way to go for the simple things in life! They can even work as a learning tool when you're first starting out. But the reason your code was failing, such as

BookedEmployeeRentalCars.show

was failing, is that there is no show in Access/Access VBA. Maybe this is from an earlier language you've used, such as straight Visual Basic! It's dangerous to assume that all commands/functions port from VB to VBA, or even from Excel VBA to Access VBA, because they don't, even when they have the same names.

To do what you were trying to do originally, you'd load the forms, set their Visible Property to False, then set this property to True to show the form. So you'd now have

BookedEmployeeRentalCars.Visible = True
 
Using the Wizards, as Paul suggested, is the way to go for the simple things in life! They can even work as a learning tool when you're first starting out. But the reason your code was failing, such as

BookedEmployeeRentalCars.show

was failing, is that there is no show in Access/Access VBA. Maybe this is from an earlier language you've used, such as straight Visual Basic! It's dangerous to assume that all commands/functions port from VB to VBA, or even from Excel VBA to Access VBA, because they don't, even when they have the same names.

To do what you were trying to do originally, you'd load the forms, set their Visible Property to False, then set this property to True to show the form. So you'd now have

BookedEmployeeRentalCars.Visible = True

I was using google to search for ways to make it work and all of the examples I found used the .show to make the forms work. I do have it working now with the wizard so I am happy with it. Thanks for the notes though!:D:D
 

Users who are viewing this thread

Back
Top Bottom