Can't access the "List box" from my "Form" (1 Viewer)

nick07

New member
Local time
Today, 15:18
Joined
Sep 5, 2023
Messages
3
Problem Layout:
I have a "Form" and inside this form i have a "Subfrom" and a "List Box".
In the "Subfrom", i have an event action for "Dbl Click" the purpose of it is that when the user double click on a row from the records in the "Subform",, that record will be pasted in the the List Box Below.
I created the "List Box" from the Design Menu and than clicked cancel to not bound it to any table for it to be empty and not show anything until i selected a record from the "Subfrom".

Thats My VBA:

"
Private Sub Form_DblClick(Cancel As Integer)

Dim selectedID As Long
Dim strSQL As String

' Check if an item in the Subform is selected
If Not IsNull(Me.ID.Value) Then
selectedID = Me.ID.Value

' Build the SQL statement to select the record
strSQL = "SELECT * FROM Assets_Tasks WHERE ID = " & selectedID

' Add the selected record to the list box
Me.Selected_Tasks.AddItem strSQL

End If

End Sub

"

General Problem:
Im getting an error that the Method or data member not found for the list box "Selected_Tasks", The name "Selected_Tasks" i got it from selecting the The List box from design view -->Name Property
 

sonic8

AWF VIP
Local time
Today, 14:18
Joined
Oct 27, 2015
Messages
998
I have a "Form" and inside this form i have a "Subfrom" and a "List Box".
So, the list box and the subform are both positioned on the form?
Then you need to include the reference to the parent (of the subform) to address the list box.
Code:
Me.Parent.Selected_Tasks.AddItem strSQL
 

nick07

New member
Local time
Today, 15:18
Joined
Sep 5, 2023
Messages
3
So, the list box and the subform are both positioned on the form?
Then you need to include the reference to the parent (of the subform) to address the list box.
Code:
Me.Parent.Selected_Tasks.AddItem strSQL
It worked thankss
 
Local time
Today, 08:18
Joined
Sep 16, 2023
Messages
35
I think that when selecting a record it should add data to the listbox, but this does not do it
Me.Selected_Tasks.AddItem strSQL
What you should add to the listbox is a row with some columns, for example Id, name and other data that would allow you to then do something with those texts, it does not add an SQL, if I understood correctly or not, you will tell me.
By the way, selecting a record with a double click will be difficult since if you touch a field, the field will be activated first unless that subform has a preview key activated and I think it is only for keys.
I normally add one more select field to select or deselect a box, and it must be in the table so that it maintains the selection even if you later delete them all, that will allow you to select better.
It also depends on what you want to do with that listbox, which humans will find strange since it does not contain the record but rather an SQL text that would bring the record once executed.
The other problem is that the subform is inside a form "A" and the listbox too, to access the listbox from the subform (which is inside the FORM "A" you must indicate Forms.A and not me.Listbox since the listbox It is not in the subform but in FORM "A" or also using parent.
If I understood correctly
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:18
Joined
Feb 19, 2002
Messages
43,275
In the "Subfrom", i have an event action for "Dbl Click" the purpose of it is that when the user double click on a row from the records in the "Subform",, that record will be pasted in the the List Box Below.
What is your actual objective? The listbox is not going to save this record if that was what you were thinking would happen.
 

Users who are viewing this thread

Top Bottom