Need help with Allen Browne search form.


A

Aria

I’m using Allen Browne’s search form in my classroom coverage db. When there
are no records to display, a message box appears stating this fact (received
code from a kind person here). It works great except when the message
appears. Once the message appears, the reset button seems disabled. It
doesn’t clear the text and combo boxes. Can anyone tell me what I need to do
to fix it? Be advised, I’m still pretty new to coding.

I don’t know exactly what you need to know, but here is the code from the On
click event:

'Purpose: Clear all the search boxes in the Form Header, and show all
records again.
Dim ctl As Control

'Clear all the controls in the Form Header section.
For Each ctl In Me.Section(acHeader).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
ctl.Value = Null
Case acCheckBox
ctl.Value = False
End Select
Next

'Remove the form's filter.
Me.Filter = "(False)"
Me.FilterOn = True

ExitHere:
Exit Sub
 
Ad

Advertisements

K

KLZA

I’m using Allen Browne’s search form in my classroom coverage db. When there
are no records to display, a message box appears stating this fact (received
code from a kind person here). It works great except when the message
appears. Once the message appears, the reset button seems disabled. It
doesn’t clear the text and combo boxes. Can anyone tell me what I need to do
to fix it? Be advised, I’m still pretty new to coding.

I don’t know exactly what you need to know, but here is the code from the On
click event:

    'Purpose:   Clear all the search boxes in the Form Header, and show all
records again.
    Dim ctl As Control

    'Clear all the controls in the Form Header section.
    For Each ctl In Me.Section(acHeader).Controls
        Select Case ctl.ControlType
        Case acTextBox, acComboBox
            ctl.Value = Null
        Case acCheckBox
            ctl.Value = False
        End Select
    Next

    'Remove the form's filter.
    Me.Filter = "(False)"
    Me.FilterOn = True

ExitHere:
    Exit Sub

need to see the code that triggers the message...
 
B

Beetle

Try refreshing the form by adding a line at the end of the
procedure for the Reset button;

Dim ctl As Control

'Clear all the controls in the Form Header section.
For Each ctl In Me.FormHeader.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
ctl = Null
Case acCheckBox
ctl = False
End Select
Next

'Remove the form's filter.
Me.Filter = "(False)"
Me.FilterOn = True
Me.Refresh '<<<<<<< new line

Also, if you don't want the user to have to click the Reset button at
all in the cases where no matching records were found, you can add
a line in the procedure for your Search button to call the Click event
of the Reset button. I'm not going to repost the entire procedure
for the Search button, just the relevant lines;

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records that match your criteria.", _
vbInformation, "No Match Found"
cmdClearAll_Click '<<<< call the Click event of the Reset button
End If

--
_________

Sean Bailey


Aria via AccessMonster.com said:
KLZA said:
I’m using Allen Browne’s search form in my classroom coverage db. When there
are no records to display, a message box appears stating this fact (received
[quoted text clipped - 29 lines]
need to see the code that triggers the message...
Do you need to see the entire code? The form works perfectly except for this
last part.

Here is the tail end of the code...
'See if the string has more than 5 characters (a trailng " AND ") to
remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria selected", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the "
AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
'Debug.Print strWhere

'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records that match your criteria.",
vbInformation, "No Match Found"
End If
End If

ExitHere:
Exit Sub
 
Ad

Advertisements

A

Aria

....and there we have it. Perfect! I couldn't call the click event of the
reset button. I must be doing something wrong, but Me.Refresh works. Thank
you very much!
--
Aria W.


Beetle said:
Try refreshing the form by adding a line at the end of the
procedure for the Reset button;

Dim ctl As Control

'Clear all the controls in the Form Header section.
For Each ctl In Me.FormHeader.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
ctl = Null
Case acCheckBox
ctl = False
End Select
Next

'Remove the form's filter.
Me.Filter = "(False)"
Me.FilterOn = True
Me.Refresh '<<<<<<< new line

Also, if you don't want the user to have to click the Reset button at
all in the cases where no matching records were found, you can add
a line in the procedure for your Search button to call the Click event
of the Reset button. I'm not going to repost the entire procedure
for the Search button, just the relevant lines;

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records that match your criteria.", _
vbInformation, "No Match Found"
cmdClearAll_Click '<<<< call the Click event of the Reset button
End If

--
_________

Sean Bailey


Aria via AccessMonster.com said:
KLZA said:
I’m using Allen Browne’s search form in my classroom coverage db. When there
are no records to display, a message box appears stating this fact (received
[quoted text clipped - 29 lines]
Do you need to see the entire code? The form works perfectly except for this
last part.

Here is the tail end of the code...
'See if the string has more than 5 characters (a trailng " AND ") to
remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria selected", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the "
AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
'Debug.Print strWhere

'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records that match your criteria.",
vbInformation, "No Match Found"
End If
End If

ExitHere:
Exit Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top