Solved

Refresh Main Form after Subform Click

Posted on 2006-10-31
18
393 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

734 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