Solved

Refresh Main Form after Subform Click

Posted on 2006-10-31
18
390 Views
Last Modified: 2008-02-01
hey guys, I have two forms... one main form and one subform.  I have the following code:

If MsgBox("Are you sure this information is accurate?  You cannot edit changes once they are submitted to the Control Sheet.", vbOKCancel) = vbOK Then
        DoCmd.GoToRecord , , acNext
        Forms!frmControlProd.Requery
        Exit Sub
Else:
    Exit Sub
End If

For some reason, this refreshes the main form just fine, but instead of making the subform go to a new record (as I wanted with DoCmd) it sends it to the first record.  Is there something I can add to make the subform go to a new record as well?
0
Comment
Question by:JeffGMACI
  • 10
  • 8
18 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17843057
try this if u want the subform to go to a new record

DoCmd.GoToRecord , , acNewRec
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17843073
note, the other way to refresh the parent, without specifying the form name is

Me.PArent.Requery
0
 
LVL 2

Author Comment

by:JeffGMACI
ID: 17843078
It still goes to the first record in the table that the subform is linked to if I use that.... i'm wondering if I need to set the focus back to the subform and then go to the new record after the refresh
0
 
LVL 2

Author Comment

by:JeffGMACI
ID: 17843098
Well, the Parent command worked as well but it still sets the subform's record to the first record and not a new one
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17843122
the setfocus might do the trick

try setting focus to a field in your subform

somefield.SetFocus

then do the acNewRec
0
 
LVL 2

Author Comment

by:JeffGMACI
ID: 17843146
well, that set them BOTH to new records!  haha I've done everyone but the one I want :)
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17843154
LOL!!!
hang on
0
 
LVL 2

Author Comment

by:JeffGMACI
ID: 17843183
So weird!  If I don't requery it goes to the next record just fine.  
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 17843212
i have to give the form focus


        DoCmd.GoToRecord , , acNext
        Me.Parent.Requery
        Me.Parent.<<nameofsubformcontrol>>.SetFocus
        DoCmd.GoToRecord , , acNewRec


of course, u can use Forms!... instead


0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 65

Expert Comment

by:rockiroads
ID: 17843216
When u go into addmode in the parent, its obviously gone into addmode in the subform as well
0
 
LVL 2

Author Comment

by:JeffGMACI
ID: 17843242
Ah ha, that did it.  I see what was happening now, thanks for the help!
0
 
LVL 2

Author Comment

by:JeffGMACI
ID: 17843251
I was getting an error but I had renamed my subform and forgot to update it in the code, thanks for the assistance!
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17843285
Cool :)


as u can see, I prefer to use Me.Parent or Me.<<nameofsubformcontrol>>

when working in forms vba, its just my style. Especially as I have a habit at times to rename my forms.

Not so keen on using Forms!frmName etc, but u can still use that if u want.
0
 
LVL 2

Author Comment

by:JeffGMACI
ID: 17843383
Yeah, I like the Me also because I change them or forget that I changed them too.
0
 
LVL 2

Author Comment

by:JeffGMACI
ID: 17858779
Hey Rockiroads,
I had a weird thing happen with this.  The code we worked on works when the Main form lives in isolation (meaning, I just open it and enter.)

However, when I set a command to open it from ANOTHER form (and filter for a specific record) it gums back up.  The update part works fine, but it won't go to the new record in the subform, even though it will let me manually advance to a new record.  It's so weird, too, becuase when I break down the code into eithe:

Refresh main form
or
Advance to new record in subform

it will work for either one, but not both together!  it still works fine for both when I just open the form standalone and play with it.  Do you see anything I could be missing?

Jeff
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17858979
perhaps the use of

me.parent.subform

is that what u r using?

if so,try this then

forms!formname etc
0
 
LVL 2

Author Comment

by:JeffGMACI
ID: 17858995
Yeah, that was the first thing I did... I switched it all to absolute names:

Forms!frmControlProd!sfEntry   etc.  I think this project is doomed haha
0
 
LVL 2

Author Comment

by:JeffGMACI
ID: 17881384
Well, I figured out a way to trick it, sort of.  Instead of refreshing the whole form, I only wanted to refresh about a dozen text boxes.  So I told the subform, on refresh, to populate the values of the 12 UNBOUND text boxes with a function.   Before, the text box values were bound to a function.  This way the main form doesn't get refreshed all together, but the necessary parts do update when they're supposed to.


Thanks for all your help!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
View vs Edit mode enhancements 12 40
Close Print Preview button not active 12 36
Change AD password via MS Access DB 2 19
VBA pass value between two fields different tables 10 37
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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 …

910 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

24 Experts available now in Live!

Get 1:1 Help Now