Form Filtered on Previous Form Record

Helping Hand
NewLounger
Posts: 13
Joined: 13 Mar 2014, 09:56

Form Filtered on Previous Form Record

Post by Helping Hand »

I would like to open a form based on the record that is on the current form.

So, when I open [frm5_Activity] with a command button, I would like it to be on the same record as [frm4_Activity.FieldID]. Can you please tell me how to do that? :hairout:

[frm5_Activity.FieldID] = [frm4_Activity.FieldID]

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Form Filtered on Previous Form Record

Post by Rudi »

Try this: DoCmd.OpenForm "frm5_Activity", , , "FieldID = " & Forms![frm4_Activity.FieldID]
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

Helping Hand
NewLounger
Posts: 13
Joined: 13 Mar 2014, 09:56

Re: Form Filtered on Previous Form Record

Post by Helping Hand »

Sorry, I'm not good at code writing. I tried to follow some of the other code patterns that appeared but I botched it up.

This is what I tried:

Private Sub Command102_Click()
On Error GoTo Err_Command102_Click


DoCmd.OpenForm [frm5_Activity], acNormal, [FieldID], [frm5_Activity.FieldID] & Forms![frm4_Activity.FieldID]"

Exit_Command102_Click:
Exit Sub

Err_Command102_Click:
MsgBox Err.Description
Resume Exit_Command102_Click

End Sub

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Form Filtered on Previous Form Record

Post by Rudi »

Access VBA is not an area I am very comfortable with (certainly not as with Excel VBA), and the syntax of Access has always eluded me (personally!).

Try this code behind the command button to open the form:

Code: Select all

Private Sub Command102_Click()
    On Error GoTo Err_Command102_Click
    DoCmd.OpenForm "frm5_Activity", , , "FieldID = " & Forms![frm4_Activity.FieldID]
Exit_Command102_Click:
    Exit Sub
Err_Command102_Click:
    MsgBox Err.Description
    Resume Exit_Command102_Click
End Sub
If the DoCmd line debugs for any reason, try any of the following variants by replacing the DoCmd line (one at a time) with the ones below.
As I say, I am not as Expert as Hans with the syntax...:smile:

Variants:

Code: Select all

    DoCmd.OpenForm "frm5_Activity", , , "FieldID = " & Forms!frm4_Activity![FieldID]
    DoCmd.OpenForm "frm5_Activity", , , "FieldID = " & Forms![frm4_Activity]![FieldID]
    DoCmd.OpenForm "frm5_Activity", , , "FieldID = " & me![FieldID]
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

Helping Hand
NewLounger
Posts: 13
Joined: 13 Mar 2014, 09:56

Re: Form Filtered on Previous Form Record

Post by Helping Hand »

Thank you Rudi. The second one worked as requested but not as expected. I'm going to have to give it more thought and go back to the drawing board.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Form Filtered on Previous Form Record

Post by Rudi »

Were you expecting something different?
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78589
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Form Filtered on Previous Form Record

Post by HansV »

Does the record source of frm5_Activity already contain a record with the same FieldID as the form containing the command button, or do you want to create a new record with that FieldID?
Best wishes,
Hans

Helping Hand
NewLounger
Posts: 13
Joined: 13 Mar 2014, 09:56

Re: Form Filtered on Previous Form Record

Post by Helping Hand »

The code that Rudi provided does take me to the new form, filtered on the same record - it was perfect. What I wanted to do with it was my bad and didn't work out right.

I like to help the community education out and the person that tracks everything has been struggling to keep all of the information straight. It's a very manual process with sports, classes, building rental, farmers market, sponsors, vendors etc. to track. I told her that I would love to help her out at no charge because they do a lot for our small community and I've always enjoyed working with Access. I could just through it together and she would still be a lot further ahead but I wanted to make it as user friendly as possible. So where I'm at is...

I have a form where she'll enter the Activities [frm4_Activities]. I have tables for the instructors, payment, participants, locations and so on. The table for the locations, which could be a classroom, soccer field, baseball diamond, building rental etc. There's a join table [tblLocations], which is used as a subform on the Activity form [frm4_Location subform]. It includes:

FieldID (combo box using tblActivityLocations)
ActivityID - join for [frm4_Activity]
InstructorID (combo box using tblInstructors)
LocationType (combo box using stblLocations)

When she goes to pick the location, I don't want her to have to scroll through all of the sports fields if what she's trying to find is one of the classrooms.

If there a way to filter [tblActivityLocations.FieldID] on whatever is selected in [LocationType]?

User avatar
HansV
Administrator
Posts: 78589
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Form Filtered on Previous Form Record

Post by HansV »

Best wishes,
Hans

Helping Hand
NewLounger
Posts: 13
Joined: 13 Mar 2014, 09:56

Re: Form Filtered on Previous Form Record

Post by Helping Hand »

Thank you Hans. I'll give it a try.

User avatar
HansV
Administrator
Posts: 78589
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Form Filtered on Previous Form Record

Post by HansV »

Feel free to post back if you need more specific help.
Best wishes,
Hans