Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ms Access VBA Button Properties

Status
Not open for further replies.

magi

Programmer
Nov 20, 2001
13
US
I have two list boxes(left and right) and a button to send all the items in the left to right when i press it. I wanted to know how do i disable this button when the left contains no items.

I use this code for button
Private Sub AddAll_Click()
Dim strItems As String
Dim intItem As Integer
For intItem = 0 To lstLeft.ListCount - 1
strItems = strItems & lstLeft.Column(0, intItem) & ";"
Next intItem

Call FillList(LstRight, strItems)
Call FillList(lstLeft, "")

If (lstLeft.ListCount = 0) Then
AddAll.Enabled = False
End If
End Sub

Error message is i cannot use Addall.enabled property in side the onclick function
 
Hi,

You can't disable the button in the middle of an event triggered by the button. What you will want to do here is take the iff statement and put it on top like this:


Private Sub AddAll_Click()
If (lstLeft.ListCount > 0) Then
Dim strItems As String
Dim intItem As Integer

For intItem = 0 To lstLeft.ListCount - 1
strItems = strItems & lstLeft.Column(0, intItem) & ";"
Next intItem

Call FillList(LstRight, strItems)
Call FillList(lstLeft, "")

End If
End Sub

So if there is something there it performs its function, and if not it skips on by as if there was no code there.

Hope this helps

Kyle ::)
 
Thankyou very much, but my questions is what can i do to disable my button when the left list becomes empty. i mean when i click the button all the items in the left list are moved to right. As soon as this happens my button should be disabled
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top