Adding RowSourceType and RowSource to a listbox (1 Viewer)

jpl458

Well-known member
Local time
Today, 12:59
Joined
Mar 30, 2012
Messages
1,038
I have form (Researchfm) that has canned queries that run on button click and it works just fine. But I tried adding a second form to which I can move the existing queries. In the working form there is a listbox (QryRestlylb) the displays the queries. I resize the listboox to fit query result with code that lookes like this:


Me.QryResultlb.Visible = True
Me.QryResulltb.Height = 3718.994
Me.QryResulltb.Width = 15000
Me.QryResulltb.RowSourceType = "Table/Query"
Me.QryResulltb.RowSource = "QryGroupbyCompany"
Me.QryResultlb.ColumnCount = 10
Me.QryResultlb.ColumnWidths = "1.5in;0.8in;1.0in;1.5in;1.5in;.5in;1in;1.3in;1.5in"


This code works on this form whose record source is Mastertbl3

But when I try to build the second form that code fails with a compile err on the RowSourceType and the Rowsource.

The second form is is named Queriesfm, and I set it's record source to the same as the first form. I rebuilt the buttons on the new form set to run query, and copied the code from the first form to the the Queries form, and renamed the list boc to coorespond to the listbox on the second form. That code look like this:

Code:
Me.QryResulttb2.Height = 3718.994
Me.QryResulttb2.Width = 15000
Me.QryResulttb2.RowSourceType = "Table/Query"
Me.QryResulttb2.RowSource = "QryGroupbyCompany"
Me.QryResulttb2.ColumnCount = 10
Me.QryResulttb2.ColumnWidths = "1.5in;0.8in;1.0in;1.5in;1.5in;.5in;1in;1.3in;1.5in"

I Get this error:

[ATTACH type="full"]103957[/ATTACH]

In this line of code:

[CODE]Me.QryResulttb2.RowSourceType = "Table/Query"

Can't figure it out, why it works on the first form but not the second.
 

Attachments

  • 1666200209021.png
    1666200209021.png
    6.3 KB · Views: 71

jpl458

Well-known member
Local time
Today, 12:59
Joined
Mar 30, 2012
Messages
1,038
Tried to edit thread but didn't take. The SQL for the above is that same for both forms:
Code:
SELECT RoboMasterTbl3.companyname1, RoboMasterTbl3.calldate, RoboMasterTbl3.callclass, RoboMasterTbl3.[1stcontact], RoboMasterTbl3.[2ndcontact], RoboMasterTbl3.[3rdcontact], RoboMasterTbl3.callingnumber, RoboMasterTbl3.personemail, RoboMasterTbl3.personcallbackno
FROM RoboMasterTbl3
GROUP BY RoboMasterTbl3.companyname1, RoboMasterTbl3.calldate, RoboMasterTbl3.callclass, RoboMasterTbl3.[1stcontact], RoboMasterTbl3.[2ndcontact], RoboMasterTbl3.[3rdcontact], RoboMasterTbl3.callingnumber, RoboMasterTbl3.personemail, RoboMasterTbl3.personcallbackno
ORDER BY RoboMasterTbl3.calldate;

It works on both forms, but in the second I can't set the recordsource for the listbox.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:59
Joined
Feb 28, 2001
Messages
27,188
Your first problem is that .RowSource is not a property of a form; it is a property of controls such as ListBox or ComboBox. Therefore, using a property such as .RowSourceType is also going to fail for forms.

Here is a link to the documentation on forms, which will allow you to see the properties you can use.


SUPPLEMENTAL EDIT: .RowSourceType is how you can put a query or a literal list in the ListBox or ComboBox, but you can't do that literal list with forms. That has to be either raw SQL or a named query.
 

jpl458

Well-known member
Local time
Today, 12:59
Joined
Mar 30, 2012
Messages
1,038
In the code I am trying to set the rowsource of a list box, not a form.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:59
Joined
May 21, 2018
Messages
8,529
On my first look I am not seeing anything. However, I have seen it where if I paste code I get weird problems. I think unseen stuff gets added. Delete the code and retype by hand. I have seen where retyping a simple line of code the exact same way works.
 

Users who are viewing this thread

Top Bottom