This is a generic procedure to allow a form to be opened and a value entered.
Because this is generic and I really do not want to write public functions to wrap the private event functions on the form, I am using setfocus and sendkeys to click buttons.
My first call works, the second does not.
Any insight would be greatly appreciated.
Access 2010
Because this is generic and I really do not want to write public functions to wrap the private event functions on the form, I am using setfocus and sendkeys to click buttons.
My first call works, the second does not.
Code:
Sub FormNav(strForm As String, varKey As Variant, strControlName As String)
Dim frm As Form
DoCmd.OpenForm strForm, acNormal
Set frm = Forms(strForm)
Select Case frm.Controls(strControlName).ControlType
Case acListBox, acComboBox
With frm.Controls(strControlName)
If .LimitToList Then
Dim RS As DAO.Recordset
Dim strkey As String
Dim strCriteriaValue As String
Set RS = CurrentDb.OpenRecordset(.RowSource)
strkey = RS.Fields(.BoundColumn - 1).Name
Select Case RS.Fields(.BoundColumn - 1).Type
Case dbMemo, dbChar, dbText
strCriteriaValue = """" & varKey & """"
Case dbDate
strCriteriaValue = "#" & varKey & "#"
Case Else
strCriteriaValue = varKey
End Select
If DCount(strkey, .RowSource, strkey & " = " & strCriteriaValue) = 0 Then
'Value does not exist in drop down
'Click New button to add new record
frm.Controls("btnNew").SetFocus
SendKeys ("{Enter}") 'Fires btnNew_Click on form
GoTo FormNav_Cleanup 'Skip looking up
Else
'Continue
End If
End If
.SetFocus
.Text = varKey
SendKeys ("{Tab}") 'can't call private after update events from another procedure, this or have to write public function to call private procedure.
[red]
'Click Edit button to edit existing record
frm.Controls("btnEdit").SetFocus
SendKeys ("{Enter}") 'does not seem to do anything
'hitting enter after code runs, fires click event[/red]
End With
Case Else
frm.Controls(strControlName) = varKey
End Select
FormNav_Cleanup:
Set frm = Nothing
End Sub
Any insight would be greatly appreciated.
Access 2010