Can SENDKEYS be used with a variable?

M

Marv Keane

I am trying to use the following sendkeys command to step down a variable
number of lines:

SendKeys "{DOWN X}", True ' MOVE DOWN X NUMBER OF RECORDS OR LINES

I am getting an error. What's the correct syntax if I need to use a variable?

Thanks in advance.
 
6

'69 Camaro

Hi, Marv.

Try something like the following:

X = 4
SendKeys "{DOWN " & X & "}", False ' Move down to 4th row.


Or if you want to use a loop that may terminate early depending upon a
certain criteria, try:

For idx = 0 To (X - 1)
SendKeys "{DOWN}", False ' Move down to next row.

If (certain_criteria) Then
Exit For
End If
Next idx

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)

- - -
When you see correct answers to your question, please sign in to Microsoft's
Online Community and mark these posts, so that all may benefit by filtering
 
J

John Spencer (MVP)

What are you trying to do? Using SendKeys is usually not the best solution.

It is best to avoid SendKeys if you can; but IF you cannot, then you would need
to use a loop to do this. Probably something like:

Dim X as Integer
Dim iLoop as Integer

For iLoop = 1 to X
SendKeys "{DOWN}", True
Next iLoop
 
D

David C. Holley

Encapsulate it in a loop

for i = 1 to x
SendKeys
next i

But, I would ask - What are you trying to accomplish? What is going on
that you need to setp down a number of lines? What's the big picture here?

David H
 
S

SacCourt

Dim I as String

I = "{DOWN 2}"

Sendkeys "SendKeys "{DOWN}" & I & "{DOWN}", True

Good examples for For Next Loops. However, SendKeys can be used to have
variables in the comand.
 
Top