Solved

Refresh Main Form after Subform Click

Posted on 2006-10-31
18
394 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
[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
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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
 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

624 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