vba to click on a list box

J

joemeshuggah

what is the vba code that would cause a list box to be clicked?

i am trying to get a particular list box to populate based on a query of
another list box; it works fine, but only if the list box that is being
queried is clicked on.
 
D

Dirk Goldgar

joemeshuggah said:
what is the vba code that would cause a list box to be clicked?

i am trying to get a particular list box to populate based on a query of
another list box; it works fine, but only if the list box that is being
queried is clicked on.


Do you really need the list box to be clicked on, or is it just that you
need to have something select in the list box? If you just need something
to be selected, is the list box in single-select or multiselect mode?

If you need the list box to be actually clicked on, is it because you have
code in the Click or AfterUpdate event of the list box that executes your
requery? If that's the case, please post the code.
 
J

Jack Leach

I don't know that it's possible to force the listbox to be clicked. But, I
think you can make a call to the onclick sub:

Call Form_OnClick

Although, I have to wonder why this will only work if the listbox is clicked
on. Why not just move the code in the click event to a function private to
the form's module and reference it from any event you want at that point.
And how would you plan on running the code that would 'click' your listbox?
There has to be some event for this code to run...


hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
J

joemeshuggah

i just need to have something selected in the box....this code works fine but
does not update the ad name unless i click on the ad id list box

Option Compare Database

Private Sub RepNm_AfterUpdate()
RepNMAD = ""
RepNMAD.Requery
RepNMAD.SetFocus
End Sub

Private Sub RepNMAD_AfterUpdate()
ADNm = ""
ADNm.Requery
End Sub
 
D

Dirk Goldgar

joemeshuggah said:
i just need to have something selected in the box....this code works fine
but
does not update the ad name unless i click on the ad id list box

Option Compare Database

Private Sub RepNm_AfterUpdate()
RepNMAD = ""
RepNMAD.Requery
RepNMAD.SetFocus
End Sub

Private Sub RepNMAD_AfterUpdate()
ADNm = ""
ADNm.Requery
End Sub


Please answer these questions:

1. Which list box is it that you want to programmatically select something
in?

2. Is that list box in single-select mode or multiselect? (Refer to the
control's Multi Select property, on the Other tab of its property sheet.)

3. What value from its list would you want to be selected? The first one?
 
J

joemeshuggah

i answered in line below

Dirk Goldgar said:
Please answer these questions:

1. Which list box is it that you want to programmatically select something
in? RepNMAD; the user would select the rep name from the RepNM drop down, which currently automatically populates the RepNMAD drop down with the ad id. the intent was for this value to automatically populate the ad name in the next list box (ADNm). it currently does, but only if i manually click on the RepNMAD list box.

2. Is that list box in single-select mode or multiselect? (Refer to the
control's Multi Select property, on the Other tab of its property sheet.) it is set to "None"...i tried changing this property, but when I did the ad name stopped appearing in the ADNm list box, even after manual click of RepNMAD.

3. What value from its list would you want to be selected? The first one? the value to be selected (clicked) in RepNMAD is based on a query of RepNM...it automatically populates correctly


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

joemeshuggah said:
i answered in line below


Then I think this may be what you want:

Private Sub RepNm_AfterUpdate()

With Me.RepNMAD

.Requery

If .ListCount > 0 Then
.Value = .ItemData(0)
Me.ADNm.Requery
End If

End With

End Sub
 

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