SendKeys

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

I only use SendKeys in two instances:
1st) Insert the value from the same field in the previous record.

I would Double Click the Form Control to execute On Dbl Click [Event
Procedure]

Private Sub Category_DblClick(Cancel As Integer)
SendKeys "^(')", True
End Sub

Same as Pressing CTRL+APOSTROPHE (') on the keyboard

This code does not execute in Access 2007 like it did in Access 2003
---------------------------------------------------
I was going to try the "SendKeys Macro Action" in a Macro.

I'm at a loss how to enter the "Ctrl" keystroke in the Keystrokes box in the
Action Arguments. (equivlent of pressing CTRL+APOSTROPHE)

2nd) The other instance I use SendKeys is to enter Todays Date:
Private Sub DateCompleted_DblClick(Cancel As Integer)
SendKeys "^(;)", True
End Sub

Any Suggestions?
 
Ron said:
I only use SendKeys in two instances:
1st) Insert the value from the same field in the previous record.

I would Double Click the Form Control to execute On Dbl Click [Event
Procedure]

Private Sub Category_DblClick(Cancel As Integer)
SendKeys "^(')", True
End Sub

Same as Pressing CTRL+APOSTROPHE (') on the keyboard

This code does not execute in Access 2007 like it did in Access 2003
---------------------------------------------------
I was going to try the "SendKeys Macro Action" in a Macro.

I'm at a loss how to enter the "Ctrl" keystroke in the Keystrokes box in
the
Action Arguments. (equivlent of pressing CTRL+APOSTROPHE)

2nd) The other instance I use SendKeys is to enter Todays Date:
Private Sub DateCompleted_DblClick(Cancel As Integer)
SendKeys "^(;)", True
End Sub

Any Suggestions?


You don't need SendKeys for either of those functions. Consider these
possible solutions:
1st) Insert the value from the same field in the previous record.

Put the following function into a standard module.

----- start of function code -----
Function fncDitto(frm As Access.Form)

On Error Resume Next

Dim strControlSource As String

With frm
If .CurrentRecord > 1 Then
strControlSource = .ActiveControl.ControlSource
If Left(strControlSource & "=", 1) <> "=" Then
With .RecordsetClone
If frm.NewRecord Then
.MoveLast
Else
.Bookmark = frm.Bookmark
.MovePrevious
End If
frm.ActiveControl = .Fields(strControlSource)
End With
End If
End If
End With

End Function
----- end of function code -----

Then you can set the On DblClick property of your Category control to:

=fncDitto([Form])
2nd) The other instance I use SendKeys is to enter Todays Date

Why not just this?

Private Sub DateCompleted_DblClick(Cancel As Integer)
Me.DateCompleted = Date
End Sub

Isn't that simpler than using SendKeys?
 
1) if your user can be trained to double click to get the previous value, it
should be just as easy to teach them Ctrl+'. either way involves a manual
action by the user...

if you want to *automatically* enter the value from the same field in the
previous record, i have some code that i use for repetitious data entry that
does that - after the first record has been manually entered in the current
data entry "session". if you're interested, i'll post back with an
explanation of my set-up.

2) if you want to enter the current date in a particular field, again, you
can automate that. it's actually easier to do; just add some code to the
form's BeforeUpdate event, as

If IsNull(Me!DateCompleted) Then Me!DateCompleted = Date

this will work when a new record is entered, or an existing record edited.
if you want to affect new records only, you can just set the DefaultValue
property of the DateCompleted control to

=Date()

or, add code to the form's BeforeInsert event, as

Me!DateCompleted = Date

hth
 
Thank You. A great Alternative...
Ron

Dirk Goldgar said:
Ron said:
I only use SendKeys in two instances:
1st) Insert the value from the same field in the previous record.

I would Double Click the Form Control to execute On Dbl Click [Event
Procedure]

Private Sub Category_DblClick(Cancel As Integer)
SendKeys "^(')", True
End Sub

Same as Pressing CTRL+APOSTROPHE (') on the keyboard

This code does not execute in Access 2007 like it did in Access 2003
---------------------------------------------------
I was going to try the "SendKeys Macro Action" in a Macro.

I'm at a loss how to enter the "Ctrl" keystroke in the Keystrokes box in
the
Action Arguments. (equivlent of pressing CTRL+APOSTROPHE)

2nd) The other instance I use SendKeys is to enter Todays Date:
Private Sub DateCompleted_DblClick(Cancel As Integer)
SendKeys "^(;)", True
End Sub

Any Suggestions?


You don't need SendKeys for either of those functions. Consider these
possible solutions:
1st) Insert the value from the same field in the previous record.

Put the following function into a standard module.

----- start of function code -----
Function fncDitto(frm As Access.Form)

On Error Resume Next

Dim strControlSource As String

With frm
If .CurrentRecord > 1 Then
strControlSource = .ActiveControl.ControlSource
If Left(strControlSource & "=", 1) <> "=" Then
With .RecordsetClone
If frm.NewRecord Then
.MoveLast
Else
.Bookmark = frm.Bookmark
.MovePrevious
End If
frm.ActiveControl = .Fields(strControlSource)
End With
End If
End If
End With

End Function
----- end of function code -----

Then you can set the On DblClick property of your Category control to:

=fncDitto([Form])
2nd) The other instance I use SendKeys is to enter Todays Date

Why not just this?

Private Sub DateCompleted_DblClick(Cancel As Integer)
Me.DateCompleted = Date
End Sub

Isn't that simpler than using SendKeys?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top