command button problem

  • Thread starter Thread starter steve a
  • Start date Start date
S

steve a

Hi
I've got a slight problem with a command button,
I want it to add a character into a combo box as you would with a key stroke
on the keyboard.
the code i use at the moment does this, however it doesn't auto complete,
but it does when i use the keyboard!
the code i'm using for the button's are:

Private Sub cmdKeyQ_Click()
lngCurPos = mlngSelStart
With Me.combo
.SetFocus
If CapLockOn = True Then
Me.combo = Me.combo & Chr(81)
Else
Me.combo = Me.combo & Chr(113)
End If
.SelStart = lngCurPos + 1
End With
lngLength = Len(Me.combo)
SetCurMoveOptions lngCurPos, lngLength
End Sub

i used to use "q" but changed this to use the chr () funciton thinking this
might be the problem but unfortunately the same result.
many thanks
 
On Thu, 8 Jan 2009 02:04:00 -0800, steve a

Chr(113) and "q" are equivalent, so you should not expect a difference
there.
This may be one of those few cases where I would use SendKeys. Try it
out.

-Tom.
Microsoft Access MVP
 
hi Tom
Tried
Me.combo = Me.combo & SendKeys("q", [false])
in place of the previous code,
however it returns a compile error:
expected function or variable.

Still a newby in VB code. where do i go from here?
Many thanks
Steve
 
On Thu, 8 Jan 2009 08:36:24 -0800, steve a

More something like:
Me.combo.SetFocus
SendKeys("q", [false])

-Tom.
Microsoft Access MVP
 
Hi tom thanks for that..
I've tried it out. capital letters are not required so just got rid of the
if statment
my code now shows

Private Sub cmdKeyQ_Click()

Me.combo.SetFocus
SendKeys("q", [false])

End Sub

but i now get a syntax error!
sorry to keep bugging you with error's... just never used send keys before !
Many thanks

--
steve adlam


Tom van Stiphout said:
On Thu, 8 Jan 2009 08:36:24 -0800, steve a

More something like:
Me.combo.SetFocus
SendKeys("q", [false])

-Tom.
Microsoft Access MVP
hi Tom
Tried
Me.combo = Me.combo & SendKeys("q", [false])
in place of the previous code,
however it returns a compile error:
expected function or variable.

Still a newby in VB code. where do i go from here?
Many thanks
Steve
 
On Fri, 9 Jan 2009 01:24:01 -0800, steve a

No bother at all. I wrote the original code too quickly. Here is a
better version:
Me.combo.SetFocus
SendKeys "q", [false]

-Tom.
Microsoft Access MVP
 
Back
Top