Sorry my earlier post ended half way through ... PC problems! Here are a few examples of SendKeys from my own databases, which may give you some useful ideas.
Tool bar button which types today's date into a field
Put this code into a module, and assign it to a tool bar button (or a button on a form if you prefer):
Code:
Public Function TypeDate()
'----------------------------------------------
'- Uses SendKeys to type today's date, in -
'- dd/mm/yyyy format, into a database field. -
'- Associated with a toolbar button. -
'----------------------------------------------
Dim strToday As String
strToday = Format$(Now, "dd/mm/yyyy") & " "
SendKeys strToday, True
End Function
Change the date format as required, and remove the following space if you don't need it.
______________________________________________
One line of code, to position the cursor at the start of a field when you click into the field with the mouse:
Code:
Private Sub MyFieldName_Click()
SendKeys ("{Home}")
End Sub
______________________________________________
Modification to the standard code which the Access wizard generates behind a button on a form, which opens another form and displays a related record:
Code:
Private Sub btnOpenAppUseForm_Click()
On Error GoTo Err_btnOpenAppUseForm_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmApplicationUse"
stLinkCriteria = "[EmployeeID]=" & Me![EmployeeID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
SendKeys (Me![EmployeeListName]), True
SendKeys (Chr$(9)), True
Exit_btnOpenAppUseForm_Click:
Exit Sub
Err_btnOpenAppUseForm_Click:
MsgBox Err.Description
Resume Exit_btnOpenAppUseForm_Click
End Sub
In my form frmApplicationUse, I have two unbound combo boxes, used to select a record to view. The Sendkeys code which I have added:
-- Sends the contents of the field 'EmployeeListName' from the original form into the first combo box on thje second form.
-- Tabs to the second combo box
(I then have some code in the second combo box which makes it drop down when you tab into it)
The result is that when the user clicks the button in the first form, the nsecond form is pre-filled with the correct name, and a list of records associated with that person drops down on screen.
______________________________________________
Another simple one ... set the focus to a combo box, then type the contents of a variable, set earlier, into it:
Code:
cmbEmployeeName.SetFocus
SendKeys (strPreviousName)
This lets you remember a value at one point in your code, then type it back somewhere else later.
______________________________________________
I hope that these examples will give you a few ideas to get you started - note that you can send:
-- Literal text
-- Keystrokes
-- contents of a string variable
... which makes SendKeys quite versatile!
Kind regards,
Bob Stubbs