Solved

Requery Based on a Checkbox

Posted on 2006-06-29
20
382 Views
Last Modified: 2012-05-05
I have a form that contains two subforms.  What I am trying to do is have a user select accounts on subform 1 that are delinquent and after they click the box for that record to indicate Yes, I would like the other subform, subform 2,  to populate with that account so they can enter the reason it is delinquent.  I know I have to use VBA Requery but I can not get it to work.  The only way that subform2 populates is if I close and reopen.  Could someone advise how to do this?  Thank you in advance.
0
Comment
Question by:BigCat53
20 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17008801
u could try this on the AfterUpdate event of that chkbox in subform1

private sub chkBox_AfterUpdate

    if chkBox.Value = True then  Me.Parent.<<nameofsubform2>>.form.Requery

end sub

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17008863
some more info for u

I have always preferred using Me.Parent or Me.subform but thats just me.

The other way of course is to use forms!formname!... etc

here is a useful guide for you

http://www.mvps.org/access/forms/frm0031.htm

0
 
LVL 26

Expert Comment

by:dannywareham
ID: 17009120
That was gonig to be my link   :-)
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17009186
So Sorry. I'll try to be slower next time :)
0
 

Author Comment

by:BigCat53
ID: 17009298
When I use:

private sub chkBox_AfterUpdate

    if chkBox.Value = True then  Me.Parent.<<nameofsubform2>>.form.Requery

end sub

I get the following error message:

Run-Time error '424'
Object Required
0
 

Author Comment

by:BigCat53
ID: 17009380
I get the error message after putting in the form name for the subform 2.  
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17009385
urm, did u change <<nameofsubform2>> to be the name of your subform?

it has to be the control name

if in your vba window for your main form
u typed in Me.
it brings up a list, u can then find the name given to your subform
or of couse look it up design mode
0
 

Author Comment

by:BigCat53
ID: 17009549
I do have the proper subform name
0
 

Author Comment

by:BigCat53
ID: 17009591
This is my code that I am using:

Private Sub Past_Due_AfterUpdate()
If chkBox.Value = True Then Me.Parent.Engineered_System_PD.Form.Requery
End Sub


Engineered_System_PD is the name of subform 2.  I have the code in the After Update event for the checkbox in Subform 1.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17009620
How are your subforms presented

Are they both subforms from one form
or is subform2 a subform of another subform  (man after several beer's that sentence would do your head in!)
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 65

Expert Comment

by:rockiroads
ID: 17009750
if subform2 is a subform of subform1
u can do this

Me.Engineered_System_PD.Form.Requery
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17009756
or look at the link provided and try the various methods there
0
 

Author Comment

by:BigCat53
ID: 17010498
Nothing is working.

Main Form: Accounts Past Due
Subform1: System_Accounts_Past_Due
Subform2: Manager_Accounts_Past_Due

Subforms are both subforms of Main form, but they are based on different querys (not sure if this matters).  When the checkbox is clicked "yes" in subform1, I want That account to show up in Subform2.  I put the following code in the Afterupdate event for the checkbox:

If chkBox.Value = True Then Me.Parent.Manager_Accounts_Past_Due.Requery

But I continue to get this error message:  Run-Time error '424'     Object Required

I don't know where to go from here.  Obviously the code is wrong or the forms are linked wrong, but how do i know?  Thank you for future assistance.
0
 
LVL 4

Expert Comment

by:Carl2002
ID: 17010745
Private Sub Past_Due_AfterUpdate()
If chkBox.Value = True Then Me.Parent.Engineered_System_PD.Form.Requery
End Sub

Do you need the extra dot after the word parent ?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17011259
is chkBox the name of your checkbox field? I assume its Past_Due based on the AfterUpdate function?
If Past_Due is the checkbox, then do this


Private Sub Past_Due_AfterUpdate()
    If Past_Due.Value = True Then Me.Parent.Engineered_System_PD.Form.Requery
End Sub


Wotcha Carl!
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 17011411
You a space after manager and before underscore:
               If chkBox.Value = True Then Me.Parent.Manager_Accounts_Past_Due.Requery
If space is intended, it requires brackets; oterwise eliminate.
0
 

Author Comment

by:BigCat53
ID: 17011849
with the new code I get the following error message:

Run-Time error '2465'
Application-defined or object-defined error

any thoughts?
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 300 total points
ID: 17015796
ok, lets try specifying the full form object

u con confirm this with the link provided


Private Sub Past_Due_AfterUpdate()
    If Past_Due.Value = True Then Forms!Mainform!Subform2.Form.Requery
End Sub

substitute MainForm with the name of your mainform
Subform2 with the name of the form u want to requery

now the names u put here are actual names of the form, not the name given the the control on the form

If there are spaces, do what PDB says, wrap with square brackets

Private Sub Past_Due_AfterUpdate()
    If Past_Due.Value = True Then Forms!Mainform![Subform2].Form.Requery
End Sub
0
 

Author Comment

by:BigCat53
ID: 17017102
that did it.  thank you for your assistance.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17017741
no probs
The other way should work as well, not to worry
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now