PDA

View Full Version : Solved: Writing Data into a Textbox On Hover



Zephid15
03-06-2007, 09:07 AM
I have a form where i do not have much room for the full description of a product. I have some room bellow where i have set up two text boxes. one for the product name and the other for the description. i would like to fill thoes textboxes with the data corrisponding to the price and item number that i am hovering over.



Private Sub txt1c_enter() 'enters data into Name and description text boxes at bottom
txtDes.Value = txt1c.Value
txtName.Value = txt1b.Value
End Sub
Private Sub txt2c_Enter() 'enters data into Name and description text boxes at bottom
txtDes.Value = txt2c.Value
txtName.Value = txt2b.Value
End Sub
Private Sub txt3c_Enter() 'enters data into Name and description text boxes at bottom
txtDes.Value = txt3c.Value
txtName.Value = txt3b.Value
End Sub
Private Sub txt4c_Enter() 'enters data into Name and description text boxes at bottom
txtDes.Value = txt4c.Value
txtName.Value = txt4b.Value
End Sub
Private Sub txt5c_Enter() 'enters data into Name and description text boxes at bottom
txtDes.Value = txt5c.Value
txtName.Value = txt5b.Value
End Sub
Private Sub txt6c_Enter() 'enters data into Name and description text boxes at bottom
txtDes.Value = txt6c.Value
txtName.Value = txt6b.Value
End Sub


as you can see above, i have it working correctly when i click in the textboxes but i would like it more dynamic then that. is this possible?

Tommy
03-06-2007, 09:55 AM
I think I would start with a class and in the withevents (enter) call the code below (which needs to be modified for you stuff). Be carefull with the withevents to not add for the wrong textboxes.


Sub SetTextText()
mId = Val(Replace(ActiveControl.Name, "txt", ""))
Select Case mId
Case 1
txtDes.Value = txt1c.Value
txtName.Value = txt1b.Value
Case 2
txtDes.Value = txt2c.Value
txtName.Value = txt2b.Value
Case 3
txtDes.Value = txt3c.Value
txtName.Value = txt3b.Value
Case 4
txtDes.Value = txt4c.Value
txtName.Value = txt4b.Value
Case Default
txtDes.Value = ""
txtName.Value = ""
End Select
End Sub


Hope that at least helps a little :)

Zephid15
03-06-2007, 10:13 AM
im just wondering if its possible to trigger something to happen depending on where your cursor is.

fumei
03-06-2007, 10:34 AM
1. txt1c, txt2c are not very good names. They do not describe anything.

2. why are you using textboxes for Name and Des (description I am assuming)? Textboxes are for user input. If the user is not entering text into the boxes - YOU are - then use labels.

3. you are using the _Enter event to put the Value into the textboxes (again...use Labels). Say the textbox txt1c (whatever THAT is) is blank - as the user has not typed anything in yet. That will put blank into txtDes, and txtName.

4. What do you mean by "dynamic"? You mentioning "hovering". There is no MouseOver event. There IS however, a MouseMove event. It fires when the mouse is moved over the control.Sub TextBox1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)

Label1.Caption = "Hello, the mouse is over Textbox1"
End SubThis changes the caption of Label1 to the text when the mouse is moved over the control, Textbox1.

This could be changed to:Sub TextBox1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)

Label1.Caption = Textbox1.Text
End Subwhich would make the Label1.Caption the contents of Textbox1.

BUT....

It does not change it when you move the mouse away. You could use logic to work on that.Sub TextBox1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)

Select Case X
Case 35 To 70
Select Case Y
Case 25 To 50
Label1.Caption = _
"Hello, the mouse is over Textbox1"
End Select
Case Else
Label1.Caption = ""
End Select
End Subwhich does control of the actual position of the mouse.

However, this can get very fussy, it does NOT get fired with all movements of the mouse while over the control. It fires when the mouse gets moved initially over the control, then again if it changes, but not after that.

So, really what exactly are you trying to do?

Again, unless you are actually wanting user input, do not use textboxes. Labels are used to display text on a form. Textboxes are for user input.

Zephid15
03-06-2007, 10:58 AM
1. i am using thoes names because i have set up a grid so they 1a is a quadrant pair.
2. i am using text boxes because once the data is pulled from the data base the user can adjust the data, ie: the price. say the data base says 8,999.00 but we want to force the price to quote dated 4 years ago.
3. refer to 2
4. by dynamic i mean when i start at the top of the form and drag my mouse over all of the description textboxes i want the large textbox at the bottom to show the full description as i drag over each one.

Zephid15
03-07-2007, 07:16 AM
There I just used the:


Sub TextBox1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)

Label1.Caption = "Hello, the mouse is over Textbox1"
End Sub


It worked really well, thanks!

fumei
03-07-2007, 02:07 PM
I will repeat...


description textboxes So...your users will be able to change the descriptions???? Really?? What exactly is the point of the users changing the text of your descriptions?

You want the users to be able to change the text in your "large description" textbox? Seems odd to me.

Sure if data comes in, and the user needs to possibly change it, of course a textbox is appropriate. My point is, again, if the user is NOT going to be changing text, it should not be in a textbox. Textboxes are, again, for user input.

It would seem to me - but I could very well be wrong - that any description that YOU put in, or change, should not have user changes allowed. Why would they? So if you have text that is a description, and there is no need, or point, to the users being able to change that description....it should be in a Label, not a Textbox.

But hey...it is not my userform.

Tommy
03-07-2007, 03:14 PM
I was wondering when you would know to update the database, if that is an option, or are you just trying to duplicate an old quote?

If the changes the user is making is not final how do you know what the user used?

Why not use a datagrid contol instead of a bunch of textboxes (I assume a lot of things). This is not always a good way, but with a database it is easier to work with overall. At least it can data-validate somewhat.

I, like fumei (Gerry) (I assumed again LOL), do not like the idea of a user changing anything, without some type of check and balance in place. It is asking for long weekends, late nights and an ulcer. Just because a user changed something and you can't duplicate it, to find out what is wrong/happened.

I actually wrote SetTextText for the mousemove event. :-{)

fumei
03-08-2007, 10:14 PM
Ah...kind of hard to know that since MouseMove was not mentioned.....

...but WithEvents and class modules were. MouseMove does not require any class modules, or WithEvents.

But in ANY case...yup, as far as I am concerned users are given access to changes only where they need them. If they don't need them, they don't have them. I will bend over backwards to ensure that users have everything they need.

No more. No less. That is where a good Needs Analysis comes in. Unfortunately, these are very very very very very very rarely done.