473,466 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

MS Access 2003 - Changing a Subform Based on listbox selection in Mainform

44 New Member
Great thanks to all the helpful responses I've read! Recently using MS Access after a lengthy (7-10 years) away from the tool. I apologize for posting a question that for all intents & purposes appears to have been answered several times. Unfortunately, I've tried nearly a dozen approaches that seem to work for others on this board with similar (nearly identical in some cases) problems.

I would like to navigate through records on a subform based on the selection from a listbox. Id prefer to put the listbox is on the subform, but I've had the most progress putting it on the Main form.

Mainform data tblMaster (with tblMaster.idno as key)
Subform Data tblPupil (with tblPupil.idno as key and frnKeyMaster as frnKey to Master)

On the frmMaster, I have a listbox whose recordsource is a query of the tblPupil table where tblpupil.frnKeyMaster = frmMaster.idno

On UPdate of that listbox, I have this code:

Private Sub lstFindPupil_AfterUpdate()
Dim strSQL As String
strSQL = ""
strSQL = "SELECT tblPupil.* FROM tblPupil WHERE (((tblPupil.idno)=" & lstFindPupil & "));"
MsgBox strSQL
Me.subfrmPupils.Form.RecordSource = strSQL
Me.subfrmPupils.Form.Requery
End Sub

The subform requeries to a "new record", which is clearly not the desired result. further, the new record does not grab the IDNO from the frmMaster (which works when just adding records to the subfrm conventionally).

Thanks in advance for any new suggestions.
Jul 17 '07 #1
8 5154
Rabbit
12,516 Recognized Expert Moderator MVP
1) Is idno formatted as a number? The code implies as much.
2) Is the list box bound on the correct field? i.e. the id field that you are trying to find.
Jul 17 '07 #2
NJonge01
44 New Member
Rabbit, thanks for your quick response!

Yes, I went in to confirm that the Listbox is bound by "column 1" which is tblPupil.idno in the SQL that returns the values from the listbox "lstFindPupil".

idno is an Autonumber, which seems to have all the attributes of a Long Integer.

I know this one has got to be simple. I just can't figure what I'm doing wrong.
Jul 17 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Try taking out the requery.
Jul 17 '07 #4
NJonge01
44 New Member
Unfortunately, that doesn't change the response.

One thing is interesting, the change in the recordsource seems to work only for the record that is the first record in the table underlying the subform and the listbox. Whenever I update the listbox to create "tblpupil.idno = 1", the navigation to that record works perfectly! It would be great if I had a 1 record table! LOL!

Thanks for taking a look!
Jul 17 '07 #5
Rabbit
12,516 Recognized Expert Moderator MVP
The subform control doesn't have any fields listed in its master/child properties does it?
Jul 17 '07 #6
NJonge01
44 New Member
The subform control doesn't have any fields listed in its master/child properties does it?
It did. I took them out and I'm still getting similar results. Are there rules about when you should and should not update those master/child properties?

thanks again for your willingness to share your knowledge!
Jul 17 '07 #7
Rabbit
12,516 Recognized Expert Moderator MVP
You use the master/child fields when you want to link fields between a main form and a subform. This means that you can only see records where the field match and the fields get auto-filled for you.
Jul 18 '07 #8
Rabbit
12,516 Recognized Expert Moderator MVP
I'm running out of ideas now. A couple of last things to try before calling in reinforcements.

Try:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM tblPupil WHERE idno=" & Me.lstFindPupil
If that doesn't work,

1) Compile your code and see if that brings up anything.
2) Check your references and see if you are missing any.
Jul 18 '07 #9

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

Similar topics

0
by: Sabine Oebbecke | last post by:
Hi Experts! I have several forms and reports where controls get their values with 'Forms!MainForm!Control' or 'Forms!MainForm!Subform!Control' resp 'Forms!MainForm!Subform.Form!Control' which...
0
by: P Mitchell | last post by:
Hello I would like someone to be able to help with the updating of data in a lookup list in a subform. In short, is their a VB instruction that is the equivalent of performing the action of...
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....
3
by: DFS | last post by:
I've been working around this for years (I believe), so I figured someone here might know: Why won't a crosstab query accept a value from a form reference? TRANSFORM...
1
by: Terry | last post by:
Hello, Has anyone experienced the following problem following an Upsize from Access 97 to SQL 2000 using the MS Upsize Wizard? Or can anyone see what the problem might be. Before Upsize...
3
by: Alan Lane | last post by:
Hello world: I have a Parent form with a combobox, where the user selects a Contract or Estimate number. Then, on a subform, I have a listbox that gets filled with the details of the selected...
3
by: john | last post by:
I have a form with Members and in that form a subform with Transactions. Those are linked (on banknr) 1xM which I've set in the database relations. Now I would like to copy the form and modify it....
18
by: Robert Jacobs | last post by:
Please advise... I currently have a Mainform (Customers) and a Subform (Service Requests) with a one to many relationship (one customer, many service requests) with a CustomerID that is unique...
12
by: kashif73 | last post by:
Hi, I have a subform (datasheet view) on my Mainform, where a user can enter information. I need help on how to display the required number of rows in my subform based on the number selected in...
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.