Can't access the "List box" from my "Form"

nick07

New member
Local time
Today, 06:57
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
 
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
 
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
 
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:
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

Back
Top Bottom