Point a Listbox to a Table in VBA

sja13

Professional Idiot
Local time
Today, 11:45
Joined
May 3, 2017
Messages
63
I have a simple Dialogue Form (“frmISs”) with a listbox (“lbxSelector”), and two command buttons, the usual “ cmdOK” and “cmdCancel”.

Using vba I want to “point” the listbox to a field in a Table.
I’ve tried all sorts, the latest being
Code:
  strTable = “tblItem”
  strField = “ItemName”
  With Form_frmISs
    .RecordSource = strTable
    .lbxSelector.RowSource = strField
  End With 
 DoCmd.OpenForm "frmIss", _
                 acNormal, _
                 , _
                 , _
                 , _
                 acDialog
All that happens is the Form opens with the RecordSource and RowSource it was created with.
I’ve also tried adding “.Requery” before the End With. No effect!

I assume that it is normal to modify the Form's Properties and Controls prior to actually issuing the OpenForm, as I can’t find the equivalent of “Form.Update” or “Form.Save”.

Can any kind soul point me in the right direction?
Thanks in advance….
 
How about telling us in plain English what you are trying to do --no jargon, no database, no listbox etc.
 
The listbox would look more like:

.lbxSelector.RowSource = "SELECT " & strField & " FROM " & strTable

adding brackets if there could be spaces or symbols in either. You'd do it in the open or load event of the form, not before opening it.
 
Thanks pbaldy - "Wino Moderator"? - Is Wino short for Windows, or do you have some sort of "refreshment"l related issues?
 
jdraw

In essence, I want a pop-up form with a listbox containing a particular field taken from a specific table,, where the name of the field and the name of the are supplied by VBA..
 
You would do that on the pop up forms load event not before opening the form. You can't change the design of the form in code.

(Well you can but it's fraught with issues, and won't work in a runtime environment so just don't)
 
Cheers Minty - I am now using the Load event with OpenArgs so I've access to the "Me." properties. Looking good so far!
 
Thanks pbaldy - "Wino Moderator"? - Is Wino short for Windows, or do you have some sort of "refreshment"l related issues?

Happy to help! I must admit to a fondness for the grape juice. :D
 

Users who are viewing this thread

Back
Top Bottom