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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List box feeding text box

Status
Not open for further replies.

FoxGolfer

Programmer
Jul 30, 2002
100
US
I have a list box that receives data from a table, Gifts. I also have a text box, GIFTS, and I want to be able to add multiple gifts per person. I have the following event written in the lsbGifts dbl click event:

Private Sub lsbGifts_DblClick(Cancel As Integer)
If Len(Me.Gifts) = 0 Then
Me.Gifts = Me.lsbGifts
Else
Me.Gifts = Me.Gifts & ", " & Me.lsbGifts
End If
End Sub

When I dbl click on the lsbGifts, I receive an error message;

The expression ON DBL CLICK you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name.

Plus, it erases the first choice and replaces the first choice with the second choice; it should be additive.
Any help would be appreciated. (Access newbie)
(It also makes a selection on single click too. ??)
 
Try this. If you have problems, then it may be that the field is bound to an underlying Control Source and that might be a problem.
But if the controls are unbound, then this will work.

Code:
Private Sub lsbGifts_DblClick(Cancel As Integer)

    If IsNull(Me.Gifts) Then
        Me.Gifts = Me.lsbGifts
    Else
        Me.Gifts = Me.Gifts & ", " & Me.lsbGifts
    End If

End Sub

Paul
 
Paul,
I inserted your code and I did not get the error message but it is not adding the second or third selection; it just replaces the existing selection. ??

Tom
 
Paul,
I take the error message back. I just tried it, again, and I still get the error message. I tried changing it to click, and double click with the same results.
I checked and the Me.Gifts is bound to a field in the underlying table, Family.gifts.
 
You may consider to delete lsbGifts and recreate it as it seems to be corrupted.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Paul,
I deleted lsbGifts and replaced it with a new one. I used the dbl click event and used your suggested code to fill the text box.
If I dbl click on a selection, I get the same error message. If I just single click on a selection, I do not get the error message. But either way, it replaces the previous selection; it is still not additive. ??
Also, I noticed that the first line of the event code is:
Private Sub lsbGifts_DblClick(Cancel As Integer). What's with the Cancel as Integer? The click event does not add this code. ??
 
The Cancel as Integer is used if you want to cancel an event. It only applies to some events, and would not be an issue in what we are trying to do. I'm not sure why you are having this issue. I can't seem to reproduce your error and whether my controls are bound or unbound, the code as I wrote it works in my form just fine. What version of Access are you using? Also, double check the names of your controls to make sure that they are correct. Those are the only things I can think of.

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top