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

SendKeys problem

Status
Not open for further replies.

kchernak

Technical User
May 28, 2002
32
0
0
US
Is it me or what?
I have a form that containes a memo field which, if the user clicked the 'edit' button, code automatically prepends the user's vba.username and the present date at the beginning of the field, and positions the insertion point for the user following this user/date stamp (i.e. JSmith 04/14/2003: ) but before the last user/date entry (so most recent comment always reside at top of field).

problem is, for some reason the numlock key gets tripped off (tried vba.sendkey'ing it back on - no luck) as soon as the 1st sendkey statement is read.

any clues would be a life saver. Thanks!

Here's the code:

Private Sub Underwriter_Comments_Enter()
Me!Underwriter_Comments.SelStart = 1

If Me!UndoChanges.Enabled = True Then
Me!Underwriter_Comments.SelStart = 1
Me!Underwriter_Comments = VBA.Environ("username") & " " & Date & ": " & vbCrLf & Underwriter_Comments

Me!Underwriter_Comments.SelStart = 1
VBA.SendKeys "^{home}"
VBA.SendKeys "{end}"
VBA.SendKeys "{left}"

End If
 
That was a problem with A97. I don't think it occurs in A2000 but it's been a while since I've heard anyone complain about it.
Try changing your code to this

Private Sub Underwriter_Comments_Enter()
Me!Underwriter_Comments.SelStart = 1

If Me!UndoChanges.Enabled = True Then
Me!Underwriter_Comments.SelStart = 1
Me!Underwriter_Comments = VBA.Environ("username") & " " & Date & ": " & vbCrLf & Underwriter_Comments

Me!Underwriter_Comments.SelStart = Len(VBA.Environ("username") & " " & Date & ": ")

See if that gets you close.

Paul
 
Thanks Paul

The numlock now stays on as desired but the insertion point does not reposition itself to the end of the 1st line following the user/date stamp. You mentioned it was an A97 issue which probably explains why it worked fine when I developed it in A2000 but failed when I converted it it A97. Interestingly, I found that if I put a msgbox line at the top of the code you provided the insertion point ends up exactly where it should. go figure. It's a user anoyance, but I guess its the lesser of two evils.
 
I'm not 100% sure where you actually want the insertion point. What I gave you should put the insertion point right
UersNameHere 4/15/03:[Here]
If you could clarify exactly where you want it, we might be able to get there without using the SendKeys. If we can get rid of the MsgBox that would probably make everyone happier.

Paul
 
Thanks Paul

You are correct - what I tried to accomplish was to have the insertion point end up at "x" as follows:

JSmith 04/14/2003: x

if the memo field is empty, it (incorrectly) ends up in position 1 line 2:

JSmith 04/14/2003:
x

if the field contains prior comments, text (my brackets added for clarity) is incorrectly highlighted/selected:

JSmith 04/14/20[03:
JDoe 04/13/2003: called to request additional] info etc...

the bracketed selection seems indiscriminant.

was checking MSKB but DoEvents didn't help, thinking I should hunt for a win32 API solution?

Thanks!

 
OK - more info: Using the following code works fine as long as when I click in the field I do not click at the end of whatever text may be present, or if no text is already present as long as I click on the first line/row. clicking anywhere else in the memo box field seems to cause problems. Also, holding the mouse button down a nanosecond too long on the click event if text is already present seem to be the cause of highlighting sections of text.

Me!Underwriter_Comments.SelStart = 1

If Me!UndoChanges.Enabled = True Then

Me!Underwriter_Comments.SelStart = 1
Me!Underwriter_Comments = VBA.Environ("username") & " " & Date & ": " & vbCrLf & Underwriter_Comments
Me!Underwriter_Comments.SelStart = Len(VBA.Environ("username") & " " & Date & ": ")
DoEvents
End If

Now I know why they put the $&@#&*@!$#*!! keys on the keyboard.
 
I think the first line, Me!Underwriter_Comments.SelStart =1 is messing you up. Try it just like this

If Me!UndoChanges.Enabled = True Then
Me!Underwriter_Comments = VBA.Environ("username") & " " & Date & ": " & vbCrLf & Me!Underwriter_Comments
Me!Underwriter_Comments.SetFocus
Me!Underwriter_Comments.SelStart = Len(VBA.Environ("username") & " " & Date & ": ")
End If


Paul
 
Here's my numlock problem: I use A97. I have a subform that pulls up a number when I click the 'checkbox'. At that point A97 turns off the numlock, which I need to enter more numbers.

If anyone can help, I would appriciate it.

Thanks,
M1919
 
m1919 you need to give us a little more info. How do you pull up the number when you click in the checkbox. Spell out the process a little and we may be able to help.

Paul
 
The main form is a set of customer records, showing name address phone, etc.
We have a subform that can be inserted showing the items purchased, with radio buttons that indicate if they are paying for that item.

Next is method of payment. There are fields that indicate payment by check, check number, amount... then [and this is the problem] there is a check box that gives you [from another table], the person's credit card. When that box is clicked the numlock goes off. the subform moves to another field that asks for the amount of payment.

After that the process is pretty straightforward.

Is this what you need????

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top