473,480 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Subform moving to first record after parent Listbox requery

547 Contributor
It has been 2 solid evenings now of starring at the focus going to the first record in subform "sfOrderICN" on requering a listbox on the parent form.

It worked fine when i used a subform instead of a listbox "sfOrderAvgAllQ1", on the parent form but I am trying to speed up the form when capturing.(will it help)
Somehow all the records get requeried and lose focus i think, when doing this, and then the focus goes to the first record in the subform after adding data to fields.
Expand|Select|Wrap|Line Numbers
  1. [Forms]![orderf].Form.[sfOrderAvgAllQ1].Requery  'after update event of combobox called "item_lookup" in subform called "sfOrderICN" 
Any suggested plan of action to get Access to listen to me?
Dec 13 '13 #1
13 5398
zmbd
5,501 Recognized Expert Moderator Expert
Yes, a requery on a form will force to return to the control with tab-order(0) and the record pointers to the first record, including the related subform and its controls.

Any suggested plan of action to get Access to listen to me?
Well, I know that you have NOT told us what you want; thus, I suspect you haven't told access what is you want either.

More details.
Start with OS and Office version.
Tell us what you want it to do.
Tell us what it is doing.
Be as precise as possible.
Dec 14 '13 #2
PPelle
17 New Member
Try this if the listbox is loosing its value:

Expand|Select|Wrap|Line Numbers
  1. Dim vTemp as Variant ' May change to the datatype of the bound field
  2.  
  3. vTemp=[Forms]![orderf].Form![sfOrderAvgAllQ1]
  4. [Forms]![orderf].Form![sfOrderAvgAllQ1].Requery
  5. [Forms]![orderf].Form![sfOrderAvgAllQ1]=vTemp
  6.  
Or this for bound forms:

Expand|Select|Wrap|Line Numbers
  1. Dim strBookmark as String
  2.  
  3. strBookmark=Me.Bookmark
  4. Me.Requery
  5. Me.Bookmark=strBookmark 
  6.  
Dec 14 '13 #3
zmbd
5,501 Recognized Expert Moderator Expert
PPelle
Please let us see what OP is actually wanting to do before we start offering guesses and code? You might actually be correct; however, quite often guessing just muddles the thread.

Neelsfer is normally pretty good at the details which is why I didn't delete the thread for not enough information to start with, so let him help us help him first.
Dec 14 '13 #4
PPelle
17 New Member
Yes, you're right, I had to make a guess. :) Sorry about that, I didn't see your reply before a made mine.
Dec 14 '13 #5
NeoPa
32,556 Recognized Expert Moderator MVP
Down to you now Neels ;-)
Dec 14 '13 #6
neelsfer
547 Contributor
thx guys. I use Windows 7 and office 2007 with sp's installed.
It does the requery action but i want it to return to the last record i was busy with in the subform.
This happens as soon as i select the item and it requery the listbox.
Can i force it back to the last record row before/after it loses focus?

Attached Images
File Type: jpg requery action.jpg (40.7 KB, 1975 views)
Dec 14 '13 #7
zmbd
5,501 Recognized Expert Moderator Expert
Requery might alter/destroy the bookmark.
In a DAO.Recordset, I'd store the current record's PK, requery, and them perform a obj.recordset.findfirst on the PK unless you just want to move to the last record in which case a obj.recordset.movelast

I have a database where I record historical information, parent has the stuff for the equipment, subform has the information from the history table. When I add a record I have to use an unbound form, when the record is added, I requery and obj.recordset.movelast (I'll also due a "move -3;move 3" so that the last 3 or 4 records show too)

-z
Dec 14 '13 #8
NeoPa
32,556 Recognized Expert Moderator MVP
I use subroutines from the module below (modRecPos) to help with this. Call SaveRP() from the Form_BeforeUpdate() event procedure when you know the update will go ahead, then call LoadRP() from the Form_AfterUpdate() event procedure to return the recordset to how you had it before as closely as possible.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. 'RecPos
  5. 'lngCurrentRec reflects the position of the selected record within the
  6. '              recordset.
  7. 'lngScroll     reflects the position of the selected record within the currently
  8. '              visible window.
  9. Public Type RecPos
  10.     lngCurrentRec As Long
  11.     lngScroll As Long
  12. End Type
  13.  
  14. 'SaveRP() Saves the current record and scroll position of a form.
  15. Public Sub SaveRP(ByRef rpVar As RecPos, ByRef frmMe As Form)
  16.     Dim intSection As Integer
  17.     Dim ctlVar As Control
  18.  
  19.     With frmMe
  20.         If Not .Visible Then
  21.             With rpVar
  22.                 .lngCurrentRec = -1
  23.                 .lngScroll = -1
  24.             End With
  25.             Exit Sub
  26.         End If
  27.         rpVar.lngCurrentRec = .SelTop
  28.         If .ActiveControl.Section = acDetail Then
  29.             rpVar.lngScroll = CalcScroll(frmMe)
  30.         Else
  31.             .Painting = False
  32.             Set ctlVar = .ActiveControl
  33.             Call .Detail.Controls(0).SetFocus
  34.             rpVar.lngScroll = CalcScroll(frmMe)
  35.             Call ctlVar.SetFocus
  36.             .Painting = True
  37.         End If
  38.     End With
  39. End Sub
  40.  
  41. 'CalcScroll() calculates the number of lines visible above the current record.
  42. Private Function CalcScroll(ByRef frmMe As Form) As Long
  43.     Dim lngPos As Long
  44.  
  45.     With frmMe
  46.         lngPos = .CurrentSectionTop _
  47.                - IIf(.FormHeader.Visible, .FormHeader.Height, 0)
  48.         CalcScroll = Round(lngPos / .Detail.Height, 0)
  49.     End With
  50. End Function
  51.  
  52. 'LoadRP() Refreshes/requeries and repositions the form using the values saved
  53. '  during SaveRP().
  54. Public Sub LoadRP(ByRef rpVar As RecPos, _
  55.                   ByRef frmMe As Form, _
  56.                   strControl As String, _
  57.                   Optional ByVal blnUpdate As Boolean = True, _
  58.                   Optional ByVal strType As String = "Refresh")
  59.     Dim lngTop As Long, lngSel As Long
  60.     Dim blnNewRec As Boolean
  61.     Dim ctlVar As Control
  62.  
  63.     With frmMe
  64.         If rpVar.lngCurrentRec = -1 Then Exit Sub
  65.         .Painting = False
  66.         If OnSubform(frmMe) Then
  67.             For Each ctlVar In .Parent.Controls
  68.                 With ctlVar
  69.                     If .ControlType = acSubform Then _
  70.                         If .Form Is frmMe Then Exit For
  71.                 End With
  72.             Next ctlVar
  73.             Call ctlVar.SetFocus
  74.         End If
  75.         Select Case strType
  76.         Case "Refresh"
  77.             Call .Refresh
  78.         Case "Requery"
  79.             Call .Requery
  80.         End Select
  81.         blnNewRec = (.AllowAdditions) And (.Recordset.Updatable)
  82.         Call DoCmd.GoToRecord(Record:=IIf(blnNewRec, acNewRec, acLast))
  83.         With rpVar
  84.             lngTop = .lngCurrentRec - .lngScroll
  85.             lngSel = .lngCurrentRec + IIf(blnUpdate, 1, 0)
  86.         End With
  87.         If (Not blnNewRec) And (lngSel > .Recordset.RecordCount) Then _
  88.             lngSel = .Recordset.RecordCount
  89.         .SelTop = lngTop
  90.         .SelTop = lngSel
  91.         .Painting = True
  92.         Call .Controls(strControl).SetFocus
  93.     End With
  94. End Sub
This code is used from the main modRecPos module, but I have it located elsewhere as it's more generally useful. You can include it wherever makes best sense to you ;-)
Expand|Select|Wrap|Line Numbers
  1. 'OnSubform() returns True if frmVar is open within a subform on another form.
  2. Public Function OnSubform(frmVar As Form) As Boolean
  3.     OnSubform = True
  4.     On Error Resume Next    'Then statement is executed on error
  5.     If Not TypeOf frmVar.Parent Is Form Then OnSubform = False
  6. End Function
Dec 14 '13 #9
ADezii
8,834 Recognized Expert Expert
FYI: Requerying a Form invalidates any Bookmarks set on Records in the Form, whereas Refresh will not.
Dec 14 '13 #10
neelsfer
547 Contributor
Thx everybody for the info. Will attempt these "fixes" now.
Dec 15 '13 #11
monty327
1 New Member
NeoPa, I have the exact dilemma and I tried using your code. Can you show me an example of calling it. I was assuming I could just use them in the BeforeUpdate and the AfterUpdate, but LoadRP requires the parameters. I'm uncertain how to provide them.

For example, I have a subform that requires a requery in order to return a message to a label on the parent form. Unless I run the requery, the label lags behind. But now that I requery, everytime I edit the field, it jumps to the first record.

Your tools sound like they would work perfectly.
Dec 15 '14 #12
neelsfer
547 Contributor
I struggled for days as my subform combobox uses numerous "if then" statements and validations and eventually, i started to a requery a popup form from the combobox "after update event" (popup=yes/modal=no)that contains the relevant subform. It works fine now and also does not affect performance.
Requery code:
Expand|Select|Wrap|Line Numbers
  1. Forms![Popupform].[subform].Form.Requery
Dec 15 '14 #13
NeoPa
32,556 Recognized Expert Moderator MVP
@Monty.
Feel free to post a question thread and link to this one. Also PM me if you'd like me to assist personally.

However, please ensure the question as posted makes good sense and follows the guidance of how to post questions that can be answered. Vague and general questions asking for specifics but without explaining the scenario adequately are likely to get you very little in the way of helpful responses.

I would also suggest that you read what has already been posted in here before formulating your question. Repeating answers because the OP hasn't yet read what has already been posted feels like time wasted and should be avoidable.
Dec 19 '14 #14

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

Similar topics

4
4064
by: Stuart | last post by:
Hi all, I'm trying to make a form that lets the user enter a name into a text box, and have the first record that matches that name be selected in a datasheet subform. For example, say the...
3
8557
by: kevin.jonas | last post by:
What is the line of code to select the first record of a subform? I have a form with two subforms. What you select in one subform controls what is queried in the second subform. however when the...
3
5004
by: Simon Rowe | last post by:
Probably really simple but I cant work it out... I have a list box on a form with a few records in. When I open the form the first record is sort of highlight with a dashed box, when I cursor...
5
5214
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test...
1
2490
by: BartonConstruction | last post by:
Greetings all, I have a main form (frmClients) with two subforms (subVisits) (subAccount). I got the subforms to reflect what the main form is showing by linking master and child fields (I...
0
1392
by: byuphil | last post by:
My subform is displaying records from a table. Using the master-child links I am able to pass all of the necessary keys to show the correct information. When I try to select any item from a...
1
1716
by: Henry Stockbridge | last post by:
Hi, I have a main form (bio info) with a tab control containing three pages (employment, financial and dependent, respectively.) When I move record to record on the main form, the correct...
2
3419
by: Arnold | last post by:
Hi Gurus, I am getting the error 3420 "object invalid or no longer set" at in the line -- rst.FindFirst "=" & NextPK --in the code below. I simply have a continuous main form that is, by...
3
1705
by: 6afraidbecause789 | last post by:
Kudos to anyone who can explain this one--how to duplicate a group of continuous records in a subform for use in a new subform PK ID. The 2 entry fields (combo boxes) in the subform are RoleID and...
9
3060
by: alain versa | last post by:
I have one unbound form which contains two subforms. The record source of the first subform is a table containing transaction headers. The record source of the second subform is a table containing...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7084
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...
1
6739
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
6929
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
5337
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,...
1
4779
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...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.