473,396 Members | 2,151 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,396 software developers and data experts.

Requery recordset in subform by clicking listbox on mainform

2
Hi guys,

I have following troubles. I did made an access database that worked with macros just fine so far, but I kinda mixed vba with macros and sometimes that makes it hard to combine. So I started writing the macros into vbas. For the most part that wasn't much of a problem, but following function just won't work for me.

I've got a listbox in my mainform and by screen.activecontrol it used to give a selcted value to a subform (macro: GotoRecordset). Then the recordset was requeried also by a macro. I tried different solutions so far I will only write a few down. Most of them didn't give me an error but they won't work neither. The shown recordset of the subform stays with the first record and won't change.

Expand|Select|Wrap|Line Numbers
  1. Dim sub3 As Form
  2. Set sub3 = Forms!mainform!subform.Form
  3. sub3.Visible = True
  4. sub3.RecordsetClone.FindFirst "[GSVB] = " & Me!List126
  5. sub3.Refresh
  6. sub3.Requery
(Here I tried whether refresh will give me a differnt outcome and whether the defintion of sub3 might change anything)

Expand|Select|Wrap|Line Numbers
  1. Forms!mainform!subform.Form.Visible = True
  2. Forms!mainform!subform.Form.Recordset.FindFirst "[GSVB] = " & Me!List126
  3. Forms!mainform!subform.Form.Requery
(Here I changed Me! to the full written form and substituded activecontrol)


Expand|Select|Wrap|Line Numbers
  1. Me!subform.Visible = True
  2. Me!subform.Recordset.FindFirst "[GSVB] = " & Nz(Screen.ActiveControl, 0)
  3. Me!subform.Form.Requery
(That's how it looked in the beginning, except for Recordset used to be RecordsetClone)

I have no idea what's wrong here, since there are no errors either. Still they won't change my subform.
Jun 30 '15 #1
3 2628
jforbes
1,107 Expert 1GB
RecordsetClone will make a copy of a recordset in memory for you to perform actions against. It can be a copy of the current form's Recordset, but it is only a copy. Once you have found the record you are looking for in the Clone, you then need to set that record as the Active record on the Form. A common way to do this is use a Bookmark

This is the example code from the above url. The highlighted piece is the magic that you are looking for:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFindContactName_Click() 
  2.  
  3.      Dim rst As DAO.Recordset 
  4.      Dim strCriteria As String 
  5.  
  6.      strCriteria = "[ContactName] Like '*" & InputBox("Enter the " _ 
  7.      & "first few letters of the name to find") & "*'" 
  8.  
  9.      Set rst = Me.RecordsetClone 
  10.      rst.FindFirst strCriteria 
  11.      If rst.NoMatch Then 
  12.           MsgBox "No entry found.", vbInformation 
  13.      Else 
  14.           Me.Bookmark = rst.Bookmark 
  15.      End If 
  16.  
  17.      Set rst = Nothing 
  18.  
  19. End Sub
Taking the sample code and merging it with yours would give something like this. I don't guarantee that it will work, but it probably will.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFindContactName_Click() 
  2.  
  3.      Dim rst As DAO.Recordset 
  4.      Dim strCriteria As String 
  5.  
  6.      strCriteria = "[GSVB] = " & Me!List126
  7.  
  8.      Set rst = Me.RecordsetClone 
  9.      rst.FindFirst strCriteria 
  10.      If rst.NoMatch Then 
  11.           MsgBox "No entry found.", vbInformation 
  12.      Else 
  13.           Me.Bookmark = rst.Bookmark
  14.      End If 
  15.  
  16.      Set rst = Nothing 
  17.  
  18. End Sub
Jun 30 '15 #2
MrHJL
2
I tried it but it didn't work.

Just to describe the situation again: The listbox is in the mainform and the recordset to be changed is that of a subform. I already have a functional code working that changes the recordset of the mainform from a listbox in the mainform, that is not the issue.

Could you rewrite your suggestion to a form that would do that very task @jforbes?
Jul 3 '15 #3
zmbd
5,501 Expert Mod 4TB
somewhat vague here...

If you are altering the original recordsource for the main and subforms... that is to say, you are changing the SQL that established the recordset for the form or controls regardless if it's a filter or where conditional...

then

If you change the recordsource for the mainform:
you have to force the mainform to requery
then you have to force the subform to requery

Think of the form (or control therein) as being a snap-shot (view) of the current state of the recorsource. If you alter he record set by adding, deleting, or in a multi-user environment when another user changes a record, the current records shown in the form/control do not reflect that change.

Once you have requeried the forms, then you can move to the record of interest.

However, this doesn't sound like a normal parent/child form relationship where the two forms are linked on the related fields. When done this way, going to a record in the parent form will cause the child form to show the related records.

So, what is it you are doing here?
Jul 12 '15 #4

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

Similar topics

2
by: Hey_Moe! | last post by:
I have subform which uses a SQL statement as the record source. One of the criteria (ie. Part of the WHERE condition) is a column value from a ListBox on the MainForm. Two problems exist: 1....
2
by: F. Michael Miller | last post by:
I need to requery a subform from a third form and can't seem to get it to work. frmForm1 has frmAddress as a subform. The button cmdReviseAddress opens the form frmUpdateAddress where all of my...
3
by: ken | last post by:
Hi, I have a main form with a text box and a filter button. I also have a subform in the main form. When I make an entry into the filter text box and click the filter button, I change the query...
3
by: 4004 | last post by:
I have a frmSet (I am a teacher) which has a frmSetQuestions subform, which shows a filtered set of questions. I have a lboTopic which I use in the criteria of the subform recordset to filter...
2
by: cmichaud | last post by:
Previously i had a combo box where i could select a name and then click a button and a subform on that form would requery and give me the information i wanted. However, i have now changed the...
1
by: kimj.dk | last post by:
Hi, I have a form with a subform where the subform uses the value from a combo box on the main form as a query criteria. I don't want the subform to update or get data before the user has selected...
1
by: Parasyke | last post by:
I have a subform within a tabpage that will requery/refresh (?) if I press F9 and it will update the data in the subform, but I have tried various combinations of Me!SubformName.requery...
2
by: mslagle1 | last post by:
Hi all, I am trying to requery a subform "frmOpenWorkOrders" when a value list "status" on my main form "frmWorkOrderMain" is changed. If I change "status" then click on "frmOpenWorkOrders" and...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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,...

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.