Eric58132
11-16-2010, 12:59 PM
Hi All,
I'm trying to use SendKeys to automate the search functions on a form in a database I'm building (to later give away and hopefully wipe my hands clean of).
On my form I have a text box where the user types in what they are searching for, and then a combo box listing out the names of the available controls you can search within. With these two selections, I have written the following code:
Dim SearchVariable As String
SearchVariable = Me.SearchCriteria.Value
Me.[SearchBox].SetFocus
SendKeys "^(c)", 1
If SearchVariable = "Street Name" Then
Me.[Street Name].SetFocus
ElseIf SearchVariable = "Job Number" Then
Me.[Job Number].SetFocus
ElseIf SearchVariable = "Maximo Number" Then
Me.[Maximo Number].SetFocus
Else: Me.[Town].SetFocus
End If
SendKeys "^(f)", 1
SendKeys "^(v)", 1
SendKeys "%(f)", 1
Where SearchCriteria is the combo box and SearchBox is the text box. My problem is that when I run this code, the "Look In" portion of the find and replace form defaults to the form, and not the object that I have selected based upon the 'If' statement in the code above. I have tried to use {TAB} within my SendKeys code but for some reason tab doesn't work? I was trying to use tab in this format: SendKeys "{TAB}",1 but I wasn't receiving any sort of response when running the code.
Any suggestions on how I can fix this problem would be extremely helpful. Thanks!
I'm trying to use SendKeys to automate the search functions on a form in a database I'm building (to later give away and hopefully wipe my hands clean of).
On my form I have a text box where the user types in what they are searching for, and then a combo box listing out the names of the available controls you can search within. With these two selections, I have written the following code:
Dim SearchVariable As String
SearchVariable = Me.SearchCriteria.Value
Me.[SearchBox].SetFocus
SendKeys "^(c)", 1
If SearchVariable = "Street Name" Then
Me.[Street Name].SetFocus
ElseIf SearchVariable = "Job Number" Then
Me.[Job Number].SetFocus
ElseIf SearchVariable = "Maximo Number" Then
Me.[Maximo Number].SetFocus
Else: Me.[Town].SetFocus
End If
SendKeys "^(f)", 1
SendKeys "^(v)", 1
SendKeys "%(f)", 1
Where SearchCriteria is the combo box and SearchBox is the text box. My problem is that when I run this code, the "Look In" portion of the find and replace form defaults to the form, and not the object that I have selected based upon the 'If' statement in the code above. I have tried to use {TAB} within my SendKeys code but for some reason tab doesn't work? I was trying to use tab in this format: SendKeys "{TAB}",1 but I wasn't receiving any sort of response when running the code.
Any suggestions on how I can fix this problem would be extremely helpful. Thanks!