Full Version: Button to launch a subform?
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Accipiter22
I have a form that takes up a good portion of the window. It needs a subform, but the subform is only filled out in certain rare instances, so having it take up space on the screen doesn't make much sense. I'd like to put a button on the form, that when clicked opens the subform. I tried using the pop-up property at first, but this doesn't seem to work at all. The form just sits on top of my form, and is there as soon as the main form is opened.

If this matters, the form and subform will be linked by RcID. The subform is called frmRC

Edited by: Accipiter22 on Sat Jul 11 15:48:53 EDT 2009.
jurotek
Hi,
You could try On Current of your ParentForm
Form_MySubForm.Visible = False

Then on Click of your button
Form_MySubForm.Visible = True


Edited by: jurotek on Sat Jul 11 16:29:43 EDT 2009.
Accipiter22
That's an idea....there's also a macro that has a similar effect. That's more of a hiding/revealing type of thing though, correct? using the Visible property I'd still need to have space for the subform on the main form, would I not? I was talking more like a button that makes the subform pop up in it's own window....
datAdrenaline
You can simply delete the sub-form control from your main form, since hiding it does not really free up real estate. Then you can simply modify the Form object that was set in the Source Object property of the sub-form control to disply the information you want, and set the Pop Up property to yes ... or even the Modal property to Yes ...

Then on your main form, create a command button and in the OnClick event code execute a line of code that looks something like this:

DoCmd.OpenForm "frmRC", acNormal,,"RcID=" & Me.RcID

{Note: this assumes RcID is a NUMERIC data type}
jurotek
Thanx Brent for steeping in.
Was outside having barbecue with family.
Was going to suggest something similar:
DoCmd.OpenForm "frmRC", acFormDS,,"RcID=" & Me.RcID,,acDialog

in case Parent accidentally clicked so frmRC does not looses focus
datAdrenaline
Hello Jurotek,

Adding the acDialog definately gives the form flexibility. I had suggested to set Popup & Modal to Yes to create a behavior that the OP wished for. But flexibility improves a bit with the acDialog argument since it is a temporary setting of Popup and Modal to Yes/True, thus allowing the app to open the form in a different mode also... thumbup.gif

......

The bbq sounds like a great time! ... sad.gif
datAdrenaline
Hello Accipiter22,

I just noticed my initial replay was to Jurotek dazed.gif ... so ... this is just a post to ensure you get a notification of thread activity...
Accipiter22
Thank you! works like a charm
jurotek
YW thumbup.gif
Brent and I were happy to help.
Good luck
Accipiter22
thank you very much, you were both a big help. I figured this'd be a lot harder than it turned out to be.
Accipiter22
QUOTE
YW thumbup.gif
Brent and I were happy to help.
Good luck


I'm having an odd problem now, I just noticed it. The main form actually has two subforms on it. The first subform, and then the 2nd one, which you helped me with. If I fill out the main form, then the first subform, then click that button to launch the 2nd subform, in it's new window, everything is fine. BUT if I have no data to enter on the first subform, then click the button to launch the 2nd subform, it launces fine, but it has no RcID for some reason, and the record does not save because of this. Any idea why?
jurotek
Hi,
Can you zip and upload your db, under 500 kb and no sensitive data.

I am just wondering why you doing all this lunching subforms by cmd button.
Do you have each subform in tab ctrl ?
Does each child record has RcID (FK) related to key in parent record?
Accipiter22
Hi,

I need to launch the subform seperately because there's not enough room for it on the main form I'm using. It's also not used that often.

open frmWorkoutDate. Go to a new record by hitting the button in the lower right corner of the form. in the top right corner of the form enter a date, any date you want. Then click 'enter session cardio'. You'll notice that the field workoutID (formerly RCID) does not populate on the subform that pops up. If before you clicked 'enter session cardio' you had selected an exercise name on the 1st subform, and entered a weight and rep amount for even just one record, and then clicked 'enter session cardio' the field WorkoutID would populate on the subform that pops up.
jurotek
Hi,
I am afraid that your table schema does not support what you want to achieve.
I think your process should go like this:
Workout(1)--->Excersize(N)
Excersize(1)--->Set,repetition,weight(N)
Workout(1)--->Cardio(N)

HTH
Accipiter22
QUOTE
Hi,
I am afraid that your table schema does not support what you want to achieve.
I think your process should go like this:
Workout(1)--->Excersize(N)
Excersize(1)--->Set,repetition,weight(N)
Workout(1)--->Cardio(N)

HTH


so if I put the cardio stuff on a separate table would that work? Link it back via WorkoutID?
jurotek
Hi,
>>so if I put the cardio stuff on a separate table would that work? Link it back via WorkoutID? <<

Yes. Workout can consist of N Cardios
and
Workout can have at least one exercise and each exercise consists of sets,repetitions and weight used
Accipiter22
QUOTE
Hi,
>>so if I put the cardio stuff on a separate table would that work? Link it back via WorkoutID? <<

Yes. Workout can consist of N Cardios
and
Workout can have at least one exercise and each exercise consists of sets,repetitions and weight used


one question I had: under my current setup, I had it so that clicking the button opened the subform in a new window, and the button had this code:

Private Sub Command20_Click()
DoCmd.OpenForm "sfrmCardioSets", acNormal, , "WorkoutID=" & Me.WorkoutID, , acDialog
End Sub


Why didn't that force the subform to open with WorkoutID assigned to it?




edit: Also, since I'm putting Cardio stuff in it's own table, TblCardio, should the foreign key on it go back to tblSets, or tblWorkoutDate? The table for the cario stuff is basically the same as tblWeightReps, it just needs different fields to describe the cardio parameters. TblWeightReps has a foreign key to tblSets, but I get the feeling I'm supposed to be connecting TblCardio should connect back to TblWorkoutDate

Edited by: Accipiter22 on Thu Jul 30 18:34:08 EDT 2009.
jurotek
Hi,
>>Why didn't that force the subform to open with WorkoutID assigned to it? <<
Because you didn't have Parent-->Child Relationship established correctly so your Cardio record did not
inherit the PK value from your Workout entity

WorkoutID (FK) must be in Cardio entity and therefore it'll create 1:N between Workout and Cardio
Each workout can consist of at least one cardio exercise, cardio length,intensity and equipment type

The you'd have Exercise entity with WorkoutID (FK) and other fields like:
ExercizeTypeID (FK) link to PK in entity ExercizeTypes, and other attributes functionally dependent on Exercise key

Now each exercise can have at least one set, number of repetitions and weight used
So you'd have entity like
tblSets
SetID (PK)
ExerciseID (FK)
Set
Repetions
Weight

HTH
Accipiter22
thanks! And that'll make it so that the subform opens with the WorkoutID populated?
Accipiter22
it STILL isn't working! I am baffled. If I enter a new record on the main form, and then click the button, the subform launches, but WorkoutID STILL won't populate. It won't even populate if the subform on the mainform is filled in now. I do NOT get why this won't work. I've uploaded a copy of it with the changes made. TblCardio is the new table.

Same as before, go to frmWorkoutDate, click the button in the lower right to create a new record, enter any date you want in the upper right, then click 'session cardio'. The blank textbox with white background is where the WorkoutID from the main form (the number in the black box on the main form) should be.
jurotek
Hi,
If I had to do something like this I might consider schema like this.
See Att. please
Accipiter22
see the problem I run into though is that the cardio stuff has completely different fields from weighted exercises. That's why I have it on a subform; it gets used less than the weighted exercises, and the info entered is completely different.
Accipiter22
Question: How about something in the onLoad event of the form I'm using as a subform?

Something like

Private Sub Form_Load()
Me.WorkoutID = frmWorkoutDate.WorkoutID
End Sub


But with syntax that actually works...
jurotek
Hi,
DoCmd.OpenForm "MySubform", acFormDS,,"WorkoutID=" & Me.WorkoutID,,acDialog

Make sure you have Parent/Child ® established correctly
If you want to separate cardio that's fine. Just make sure it has attribute WorkoutID (FK) related to Workout entity.

If I'd be you I'd put sfrmWorkoutDetail and sfrmCardio on Tab ctrl realated to parent Workout
You have enough room for that, instead opening subform in separate process
Accipiter22
QUOTE
Hi,
DoCmd.OpenForm "MySubform", acFormDS,,"WorkoutID=" & Me.WorkoutID,,acDialog

Make sure you have Parent/Child ® established correctly
If you want to separate cardio that's fine. Just make sure it has attribute WorkoutID (FK) related to Workout entity.

If I'd be you I'd put sfrmWorkoutDetail and sfrmCardio on Tab ctrl realated to parent Workout
You have enough room for that, instead opening subform in separate process


I'm looking into tabbing it right now, in the meantime though, I realized something. Since on my form frmWorkoutDate there is no control for SfrmCardio, I don't know how to set the parent-child relationship between the two. I have a link between the underlying tables in the relationships screen, but I don't know how to do it on the actual form, without having the subform actually being on the mainform.
Accipiter22
okay, I checked and you can't change the background color of a tab to match a form, so that's out :(
jurotek
Hi,
You can make Tab Ctrl. back style transparent
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.