Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Requery a subform

Posted on 2013-12-09
15
Medium Priority
?
1,504 Views
Last Modified: 2013-12-13
I have a form with 3 subforms.  There is no recordsource in the main form.  Subform  Master/Child links are linked to text boxes in the main form.  

In general, when I select a record in subform 1, subform 2 updates to show a new set of records based on my subform1 selection.  I then select certain records in subform2 via a checkbox in each record then run an append query via a Button On-click Event to add the records to the table in subform3.  Everything works fine except I cannot requery subform3 to show the new records.  Access does not like my Requery commands any way I put them.

 (if I exit the form then re-open the records are there).  

Can someone please help with a VBA or macro to update subform3.  Current focus is subform2 but I want to requery the records in subform3 using a macro or VBA.

Help is much appreciated.
Charlie
0
Comment
Question by:cwbarrett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
  • +1
15 Comments
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39707757
Here's a sample, attached.
db.mdb
0
 

Author Comment

by:cwbarrett
ID: 39707807
Thanks for replying, your help is most appreciated.  You did reveal my problem.  I was executing the code from a subform2 button.  When I used your code format and placed the button & code in the "form1" form it worked fine.

Is there any way of executing this code from the subform form2 ?   or does code to requery subform3 have to run from form1, the main form?

THANK YOU!
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 39707880
You can use:

Me.Parent!NameOfSubformControl3.Requery

or:

Me.Parent!NameOfSubformControl3.Form.Requery

/gustav
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 31

Expert Comment

by:hnasr
ID: 39708619
Both forms are fine for Requery, but to reference other controls, you need to use the second format:
Debug.Print Me.Parent!NameOfSubformControl3.Form.ControlName
0
 

Author Comment

by:cwbarrett
ID: 39708843
Worked great, thank you.
Charlie
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 39708895
You are welcome!

/gustav
0
 

Author Comment

by:cwbarrett
ID: 39708917
I get stuck on the easiest things...  In subform1 I want to run a query whenever there is a record selection change (I move from one record to the next) in the detail area.  Common sense tells me the "On Selection Change" event could trigger this but it doesn't.  Can you tell me how to run a query whenver I select a different record in the detail area?

Thanks
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 39708937
It's the OnCurrent event.

/gustav
0
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 2000 total points
ID: 39708991
Or maybe you don't need to run a query. Look at the sample that I uploaded. Subform2 updates automatically when another record in subform1 is selected, and there's no code.
0
 

Author Comment

by:cwbarrett
ID: 39709131
OnCurrent executed the code but it was a never ending loop that executed the code over and over.  Had something to do with the Master/Child link so  I removed the Master/Child link in this subform1 and changed the datasource from a query to an SQL select query with criteria that was formerly part of the Master/Child link.  My  form seems to be working fine now.

Thanks again.
0
 

Author Comment

by:cwbarrett
ID: 39709149
I didn't notice the other comment.  Where is the upload?  I would like to see what you did, it may work better for me.

Thanks
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39709185
> Where is the upload?  

The very first comment. After which you said that it revealed your problem.
0
 

Author Comment

by:cwbarrett
ID: 39709197
Oh.  Thought you posted another.

Thanks
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39709288
No, it's in that one. You'll see "hidden textbox" on the main form, meaning that in real application it would be with Visible=False. It takes the value from the subform1, and then it serves as the parent for subform2.
0
 

Author Closing Comment

by:cwbarrett
ID: 39717743
Thank you!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question