Hi all,
I currently use a Excel userform to show data from a access table. The data is displayed in a Listbox in the userform. I use the below VBA to allow the user to double click the entry and the data is then displayed in textBoxes/ComboBoxes.
If i run "Macro1" it will show the data in "Table1" from access and display this in "Listbox1". I then have "Macro2" that will show the data in "Table2" from access and display this also in "Listbox1" (I dont mean at the same time). The issue i'm having is the fields in "Table1" and different to "Table2" so the below double click feature doesnt work for "Table2".
What i'm looking for is, IF "Table1" is active then use "Code1" Elseif "Table2" is active then use "code2" - i hope i've explained this well enough and would greatly appreciate your help on this.
The "txt......" refers to the textboxes in the excel userform.
Code 1
Code 2
I currently use a Excel userform to show data from a access table. The data is displayed in a Listbox in the userform. I use the below VBA to allow the user to double click the entry and the data is then displayed in textBoxes/ComboBoxes.
If i run "Macro1" it will show the data in "Table1" from access and display this in "Listbox1". I then have "Macro2" that will show the data in "Table2" from access and display this also in "Listbox1" (I dont mean at the same time). The issue i'm having is the fields in "Table1" and different to "Table2" so the below double click feature doesnt work for "Table2".
What i'm looking for is, IF "Table1" is active then use "Code1" Elseif "Table2" is active then use "code2" - i hope i've explained this well enough and would greatly appreciate your help on this.
The "txt......" refers to the textboxes in the excel userform.
Code 1
VBA Code:
Private Sub Listbox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim i As Integer
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
txtID = ListBox1.Column(0, i)
txtBrand = ListBox1.Column(1, i)
txtName = ListBox1.Column(2, i)
txtContact = ListBox1.Column(3, i)
txtEmail = ListBox1.Column(4, i)
End If
Next i
End Sub
Code 2
VBA Code:
Private Sub Listbox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim i As Integer
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
txtID = ListBox1.Column(0, i)
txtDecision = ListBox1.Column(1, i)
txtStatus = ListBox1.Column(2, i)
End If
Next i
End Sub