Solved

Refresh Main Form after Subform Click

Posted on 2006-10-31
18
389 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

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.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

708 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

19 Experts available now in Live!

Get 1:1 Help Now