Full Version: Custom Search Form
UtterAccess Forums > Microsoft® Access > Access Forms
I have a form with chronological data on it. My users want three things, the first two of which I am able to provide easily:
. Make the records chronological, from oldest to newest
2. When the form opens, go to the last (most recent) record
3. When searching with CTRL-F, make the default search direction "UP" instead of "ALL"
The users would like me to find a way of changing the default search direction on the built-in search form, but something tells me that is out of my reach. Please feel free to correct me if I'm wrong. <
HAs a second option, I'm considering creating a counterfeit search form that looks and behaves the same as the existing one. I'd need to figure out how to bypass the CTRL-F feature so that when the users hit those keys, my form would open.
Does this sound feasible, or am I making too much work for myself? Any chance someone else has already made one of these?
Could creating/recording a macro provide you with the code you're looking for?
Hi Dennis
I have not tried amending the search direction on the default search pop up form, though I have made a mimic of the form to do similar. You will need an AutoKeys macro to capture Ctrl-F.
I'm not so much concerned with interrupting the CTRL-F... I'm more worried about capturing the active form/control BEFORE I open the custom Find form, so I can determine which recordset/field to search.
If I get stuck or frustrated, I may just have to use my Autokeys macro to cause CTRL-F to open a messagebox saying "don't forget to change the search direction from ALL to UP if you want to search for the most recent values" before opening the built-in Find form. <
Hi Dennis
urely to capture the current control, in the first line of the function called by your Autokeys macro (e.g.)
MacroName = ^F
Action = RunCode
Arguments = OpenCustSrch()
Public Function OpenCustSrch()
Dim strCntrl as String
Dim BolSrchDir as Boolean
strCntrl = Application.Screen.ActiveControl.Name
BolSrchDir = -1
DoCmd.OpenForm "frmCustSrch",,,,,,BolSrchDir


End Function

h! So, just have the macro call a VBA function, so you can get right into the VBA, instead of trying to learn how to do stuff within Macros! Clever!
Because an autokeys macro is global to your application, perhaps using the keydown event in the given form might better? (and the code then stays in the form).
If you set in the forms property keypreview = yes, then you can use the keydown event to intercept and take action on any key pressed. And if you set keycode = 0, then ANY other event in the form will not see nor take action on the key pressed.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   Dim strControl       As String
   Dim strFind          As String
   If KeyCode = vbKeyF And Shift = acCtrlMask Then
      KeyCode = 0       ' send key into black hole - no other code will see the key
      strControl = Screen.ActiveControl.Name    ' you may not need this
      strFind = InputBox("find what?")
      ' your find code here
      DoCmd.FindRecord strFind, acAnywhere, , acSearchAll
   End If

Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
That's a great strategy! I agree that it probably wouldn't do to have this thing pop up for EVERY form.
Right now I've got my custom find form able to find exact matches on bound textboxes. Next, I need to work out how to find partial matches. Then, what'll probably be the hardest bit: partial matches within a combobox, since the displayed text in a combobox isn't the value stored in the bound field.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.