473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to requery a comboBox on a main form from a subform and then return back to the s

3
Hello,
I am trying to requery a control on a main form from an AfterUpdate event of a control on a subform and then return back to the record and control at the subform. Instead i am returned to the first record of the subform.
When i debug, it seems correct, the record i want does show correct at the findfirst statement. but at the form the first record is returned.

Any help would be greatly appreciated.

Here is my current code

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboVersionType_AfterUpdate()
  2.  
  3. Me.Refresh
  4.  
  5.   Dim Version As Long
  6.  
  7.   'set variable to current record ID
  8.     Version = Me.VersionID
  9.  
  10.      Forms![frm3EstStep1].Form![cboVersionSearch].Requery 'Main form combobox
  11.  
  12.          'return form to original record on the subform
  13.       With Me.RecordsetClone
  14.         .FindFirst "VersionID= " & Version
  15.             If .NoMatch Then 'incase another current user deletes the record
  16.             MsgBox "Record not found!", vbCritical
  17.               Else 'go to that record on the subform
  18.              Me.Bookmark = .Bookmark
  19.             End If
  20.       End With
  21.  
  22. End Sub
Jun 5 '19 #1
7 2116
zmbd
5,501 Expert Mod 4TB
Before the me.refresh you need to capture the primary key of the record on the subform.

I personally would use the tempvars collection to store the value.

Once you have that value then you can do the findfirst method to move the pointer to the record -AFTER you do the me.(refresh/requery)

You should also be aware that me.requery and me.refresh do NOT do the same thing:
form.refresh method: (...)In an Access database, the Refresh method shows only changes made to records in the current set. Because the Refresh method doesn't actually requery the database, the current set won't include records that have been added or exclude records that have been deleted since the database was last requeried, nor will it exclude records that no longer satisfy the criteria of the query or filter. To requery the database, use the Requery method. When the record source for a form is requeried, the current set of records will accurately reflect all data in the record source. (...)
You might find this reference helpful too:
http://allenbrowne.com/ser-29.html
Jun 6 '19 #2
GeneH
3
Thank you zmbd,
I'm not sure i understand the tempvars, I'll read up on them.

Could you post the code as you would do it?
Jun 6 '19 #3
NeoPa
32,556 Expert Mod 16PB
Your explanation and question make no mention of requerying or refreshing the data in the subform yet that's the first thing in your code.

It seems likely that the problem you're describing is caused by exactly that discrepancy.
GeneH:
Could you post the code as you would do it?
No. That's not really helpful. It just saves you the effort of understanding your own work while we're here to help you do just that.

Have a crack at it yourself then post how and why if you fail.

Don't get me wrong - you've done a great job so far with your first question here. We'd like to make sure you get the best help we can offer. That does not equate to doing it for you, but rather helping you to understand what you're doing and why it's not working as you might expect.

It may well be that you need to have some clever code that returns the selection to the correct record. On the other hand it may be a complete red-herring based on your code including unnecessary lines.

By the way, it may be helpful to know that referencing a parent form - that is one that contains a SubForm control holding the current Form - can be easily and most simply achieved with a reference in the form :
Expand|Select|Wrap|Line Numbers
  1. Me.Parent.Blah
So, I suspect your reference to Forms![frm3EstStep1].Form![cboVersionSearch].Requery could actually be written instead as Me.Parent.cboVersionSearch.Requery. All Forms have a .Form property but they only refer back to the same Form object so they're entirely redundant. Where a .Form property is important is for an item such as a SubForm control. These are not themselves Forms, but they do contain one. Hence the need to refer to them separately.
Jun 6 '19 #4
zmbd
5,501 Expert Mod 4TB
Good Morning GeneH
Please check your bytes.com Inbox
I sent you a copy of a boilerplate with several links to reference sites I've found useful over the years.
Towards the bottom of that list are two links dealing with how to reference subforms, their properties, and controls.
Jun 6 '19 #5
GeneH
3
Hello zmbd,
Thanks for your response. I'm still unsure of the tempVars and how to use them. After ascertaing the difference between requery and recalc I the following works as desired.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboVersionType_AfterUpdate()
  2.  
  3. Dim Version As Long
  4.  
  5.   Version = Me!VersionID
  6.   Me.Parent.Recalc
  7.   With Me.RecordsetClone
  8.     .FindFirst "[VersionID]=" & Version
  9.     If Not .NoMatch Then
  10.        If Me.Dirty Then
  11.           Me.Dirty = False
  12.        End If
  13.        Me.Bookmark = .Bookmark
  14.     End If
  15.   End With
  16.  
  17.  
  18. End Sub
Jun 10 '19 #6
NeoPa
32,556 Expert Mod 16PB
We suggest Requery()/Refresh() and you come back with Recalc() instead. Inspired if it works. I've been working in Access quite a while now and wasn't aware of that one so you've taught me a new trick :-)

Do check it works in all cases though. There are differences between the three methods so make sure you use the one most appropriate for your needs.
Jun 10 '19 #7
zmbd
5,501 Expert Mod 4TB
Recalc Method [Access 2003 VBA Language Reference]
Using this method is equivalent to pressing the F9 key when a form has the focus. You can use this method to recalculate the values of controls that depend on other fields for which the contents may have changed.
Sorry, was traveling between states this past few days...

So long as GeneH is concerned with ONLY the calculated controls on the form then this will work; however, if we're modifying, adding, and/or deleting records this is NOT a reliable method of updating the form.
Jun 10 '19 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bill Strass | last post by:
Problem: Access main form/subform as front end to SQL Server backend. Add/edit via subforms work fine. Not so with main form. Set up a master-detail form-subform using two views linked from SQL...
0
by: Deano | last post by:
I have a main/subform arrangement which works well. The main form's parent records are about employees. The subform calculates their salary. I have now decided that the user can enter some...
1
by: Susan | last post by:
I have a bound form and subform and am trying to enter the data in both forms programatically. The Linkmaster and Linkchild properties are set. My intent is to be able to look at the data before it...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
7
by: Stu | last post by:
Hi, I have a combobox who's values change the recordsource of the form. Within this form, there is a subform, whos records also need to change pending the value in the combobox. I am able to get...
1
by: Vladimir O¾ura | last post by:
I am building a Pocket PC application in C#. I have 5 forms (1 main and 4 sub forms). The main form must always load first. The sub forms are loaded from the main form. The application is run...
1
by: Moish | last post by:
I have a form that does not have any bound fields. I want to open a subform on that form to a specific record based on the value of an unbound field on the main form. Obviously the subform is not...
0
by: farid121 | last post by:
I am trying to update the main form with each record in the subform. I have two tables Invoice and Payment table. The main form has the payment details which I need to update for each invoice...
5
by: mule1350 | last post by:
I have a main form ApplicationSubmission with the data entry property set. I'm trying to add a subform to it, that allows the user to select from a list of standard documentation the user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.