Full Version: command button on sub-form
UtterAccess Forums > Microsoft® Access > Access Forms
barrysmith83
just a wee problem i have,
I have a main booking form, when the user clicks on a command button, up pops the sub-form that was hidden. What my problem is that when i click on the command button to close the sub-form and take the user back to the main form, it doesn't work. I set up a macro to do this but it isn't working.
any suggestions?
thanks,
barrysmith83
when i run the sub-form on its own and click on the button, it works fine. would i need code to hide it when it is ran from the main form?
MickH
Barry,
see my post regarding referencing subforms. you might have to use code here. Also determine where the button is as this is important, ie is it on the parent form or subform?
Hope this helps
MickH
sredworb
Can you attach your db for a look?
barrysmith83
the button is on the sub form, i want the user to click on a button to take them back to the main form by either closing sub-form or hiding it when the button is clicked.
MickH
hmmmm,
off the top of my head Barry, try changing the focus to a field on the parent form first, then turn the visibility off on the subform.
FOr put the button to close the subform on the parent form if this is possible.
remember that the actual subform object is a member of the parent form, so you must reference it via the parent form. (does this make sense?)
barrysmith83
sorry, not too sure what u mean.
MickH
Sorry Barry,
Im a bit of a code head, so I can think of things to do in VBA but I'm stuck using macros and such.
Hopefully one of the gurus here can help you out better.
Cheers
Mick H
barrysmith83
ok no problem. can anyone else help me with my problem??
Thanks,
sredworb
Work with this, I think this might be what you are asking.
barrysmith83
yeah thanks. i basically want it to do that, but by clicking a command button instead of your check box. will work with this. thank you.
barrysmith83
what code would i use for that?
sredworb
Can you upload your db and I will show you?
sredworb
Try Using this coding
Private Sub cmdToggle_Click()
Me![NameofForm].Visible = Not Me![NameofForm].Visible
End Sub
sredworb
Work With This Buddy.
Omade it, it's very easy so don't drive yourself nuts.
Make sure you set the Visible Format Tab to No under the Subforms Property
Jerry
barrysmith83
tried what you said mate, but no joy. will i send you my database? if so how will i do it?
barrysmith83
can anyone else suggest a way of doing it?
Thanks,
barrysmith83
got it working fine mate. i decided to do it a slightly different way. cheers.
barrysmith83
my only problem now is that i have three sub-forms on my main form. they are placed one on top of the other so that it looks neat and tidy when each is opened. if i open the sub-form that is placed on top first, it opens fine. if i open the sub-form that is placed on the bottom, you can't see it as you obviously need to click the command button first to close the sub-form that is on top. is there any way around this? any suggestions?
sredworb
Here pal try this, this should be your answer.
Jerry
barrysmith83
cheers mate. what is page1 and 2?
This is my original code:-
Private Sub Toggle4_Click()
Me![Accomodation1].Visible = Not Me![Accomodation1].Visible
End Sub
how do i use this code with code i got?
Me.Page1.Visible = True
Me.Page2.Visible = False
sredworb
Get away from the toggle buttons.
Try using the Tab Control from the tool box.
All I did was entered a form as a subform on a tab control page.
Made a few command buttons with the Me.Page1.Visible = True code in the on click event.
You can have as many pages as you want, just tweak the properties a little and the page you want visible when the button is clicked should have the above code. All the other pages should be Visible = False.
For your example using the tab control method.
Me.Accomodation1.Visible = True
Me.Accomodation2.Visible = False
and so on.
If you are confused let me know, I will help you.
I have been down that road and I'm sure I will be on its path again.
Jerry
barrysmith83
Sorry mate, you have lost me. I will attach my database for you to have a look at. (Modified a bit for posting). I would also like to validate the room number to the date of checking in. eg. Room 3 is booked for the 25th Jan, if the user trys to book this room on this day- msg "room already booked". Any ideas on that?
Thanks,
sredworb
Worked on your database a little made some changes, let me know what you think.
If you need more help let me know I am working all night.
I have nothing to do tonight again.... Think God
Jack Cowley
Nothing to do, huh? Then congratulations are in order as you and your fellow officers are doing all the right things!!
ack
sredworb
Knock on Wood brother Jack.
I want to go home in the morning.
Jerry
ohyeah.gif
barrysmith83
thanks very much mate. this is very helpful. thanks for all your help! the only problem i have now is validating the room number with the date of check in. what u think?
Thanks again mate.
sredworb
Can't Help you there brother.
Good Luck..Someone here knows how to do it..
Be Patient and if need be, repost it.
Jerry
Jack Cowley
Jerry -
nother 'quiet' night with only limited mayhem in your Chicago suburb? One thing about your job is that you will NEVER run of of things to do... Stay safe!
Jack
barrysmith83
ok, thanks for all your help any way! much appreciated.
Thanks,
Jack Cowley
Barry -
id you get all your questions answered? Is your code or db working the way you want?
Jack
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.