Marcus C
Marcus C

Reputation: 169

MS Access VBA - extract listbox value on a form (using form name.)

This seemed to be working but just stopped and I'm not sure what I changed to cause this.

I have a listbox on a form. (a single select listbox).

To extract the value, I can do me.listboxName.Column(0) and that works perfectly.

However, that's not the code I want to use. (as I will reference it from another form )

Form_myformName.listboxName.Column(0)

is what I had, and it worked and now it's stopped. It still works for similar code on other forms, so I'm not sure what's happened.

If I type in me.name, it tells me correctly that my form name is "myFormName". If I type in Form_myFormName., it prompts me with the name of my list box so I know I have the names correct. However, if I try to extract the value using:

 Form_myformName.listboxName.Column(0)

it gives me a value of Null, despite the listbox having a selected value. (which I can sucessfully extract by using me.listboxname etc)

hopefully that makes sense. anyone know what I'm doing wrong?

Upvotes: 1

Views: 2599

Answers (1)

tlemaster
tlemaster

Reputation: 859

Try it this way:

Forms("myformname").listboxName.Column(0)

I hope that helps.

Upvotes: 1

Related Questions