Define Listbox value via VBA instead of query or table

D

domibud

Hi,

I post a question a couple days ago in microsoft.public.access.forms, and I
didn't get a reply.
So, here I'm asking that question again.

I have a form, say frmB, that I open with acDialog option.
The trigger that open frmB is command button on frmA.

ListboxB is in frmB.
TextboxA and TextboxC are in frmA, which define a starting and ending number.

I want ListboxB to list all value that the range is defined by TextboxA and
TextboxB.

I tried using:
CtrListboxB.ItemData(row) = X
in do until loop, where X is the value that I need to be in the ListboxB, to
no avail.

I appreciate any suggestion to help me solve this.
 
D

Dennis

In the Form Load event of frmB put this code

For i = Forms!frmA!TextBoxA To Forms!frmA!TextBoxC
ListBoxB.RowSource = ListBoxB.RowSource & i & ";"
Next i
 
D

Douglas J. Steele

Leaving out the error checking (to ensure, for instance, that there are
values in the two text boxes and that the value in TextboxA is less than the
value in TextboxC), it would be something like the following in frmB:

Private Sub Form_Load

Dim lngLoop As Long
Dim strValues As String

For lngLoop = Forms!frmA!TextboxA To Forms!frmA!TextboxC
strValues = strValues & lngLoop & ";"
Next lngLoop

If Len(strValues) > 0 Then
strValues = Left(strValues, Len(strValues) - 1)
Me.ListboxB.RowSource = strValues
Me.ListboxB.RowSourceType = "Value List"
End If

End Sub
 
D

domibud

Thanks for your advice. I'm following Douglas's advice.
I didn't know that the rowsource property can be change programmatically.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top