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

pushing a button lists a word in a text field

Status
Not open for further replies.

warby1212

Programmer
Jun 9, 2003
183
0
0
AU
Hi, I'm a complete Visual Basic bonehead, I jsut need to do one thing for a project I am working on. On a form there is a row of buttons and a text field. All I want is that when, say, button "Bicycle" is clicked, the word Bicycle appears in the text box, then when buton "Car" is clicked, the word Car appears under bicycle in the text box and so on.
Can anyone help?

Cheers Stephen

Way away in Australia
 
Why doen't you set up a Group of Check boxes? For instance Add a check box, then copy and paste it until you get all the seletions you want. Then click on one and enter the following code or something like it.
'
Private Sub chkNo_Click(Index As Integer)

'
If chkNo(0) = 1 Then text1 = "Bicycle"
If chkNo1) = 1 Then text1 = "Car"
If chkNo2) = 1 Then text1 = "Motor Cycle"
If chkNo(3) = 1 Then text1 = "Whatever"
end sub


 
Hi,
This did it

Private Sub Check1_Click()
If Check1 = 1 Then Text1 = "Bicycle"
End Sub

Thanks a million, but can you tell me why the above code for the checkbox works but not for the button?

Private Sub Command15_Click()
If Command15 = 0 Then Text1 = "Bicycle"
End Sub

Cheers Steve

Way away in Australia
 
Using Billy71's example
create an array like Billy's example.
To do this you can add a Checkbox to the form then copy it and paste it and click yes when it prompts do you want to make a control array. Then keep copy and pasting for the number of check boxes you want. In the example I will use 3. This example will only allow the user to choose one option.

Private Sub Form_Load()
Check1(0).caption = "Bicycle"
Check1(1).caption = "Car"
Check1(2).caption = "Motorcycle"
End Sub

Private Sub Command15_Click()
For i = 0 To Check1.Count - 1
If Check1(check) = 1 Then itemcount = itemcount + 1
Next
set i = nothing
If itemcount > 1 Then
MsgBox "You may only choose one item"
Exit Sub
End If
For i = 0 To Check1.Count - 1
If Check1(i) = 1 Then Text1 = Check1(i).Caption
Next
set i = nothing
End Sub

I hope this helps
 
Thanks amen1973 I'll hang onto that.
I got it working with the check boxes very well:

Private Sub Check2_Click()
If Check2 = 1 Then Text1 = "Bicycle"
End Sub

and it looks good so I might stick with that. Of course one solution leads to another problem: "Bicycle" etc is listed in the textbox but I want to add more things to the text box with each checkbox being checked, making a list. At the moment it is replacing the previous one instead of adding to it. Can you someone help me with that?

Steve

Way away in Australia
 
I think this is maybe what you are looking for, I am not at my computer, cannot test....

You will need to set the Multiline property of Text1 to True, then modify your code as follows:

Private Sub Check2_Click()
If Check2 = 1 Then Text1.text = Text1.text & "Bicycle" & vbCrlf

End Sub

And so on for each of your check boxes. Just substitute "Bicycle" for whatever you want.

Hth
 
private sub cmdBicycle_Click()
text1.text = "Bicycle"
end sub

etc... gdlk ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top