recording Macros

  • Thread starter Thread starter NukeEng85
  • Start date Start date
N

NukeEng85

I've looked in the help section to no avail, can you record a Macro in
Access? I want to record myself making a form "filter by form" and then
selecting "apply filter/sort" or else does anyone know a code that will do
these steps? I want to add them to a command button I've already made.
 
Unfortunately MS access does not have a macro recording ability.

however in virtually all cases you can certainly code your solution, it's
just a little bit more difficult.

let's assume you have a unbound text box on a form called city, and you want
to filter the form to all those cities.

You can simply enter the city into he text box and then go:

Me.Filter = "City = '" & Me.txtCity & "'"
Me.FilterOn = True

Keep in mind if you're searching for text type field you have to surround it
with quotes as above.

in many cases perhaps it's better to prompt the user first for what you want
a search for and display the results on a form. then the user can click
on to view edit the one record. I have a couple screen shots and some
ideas about this here:

http://www.members.shaw.ca/AlbertKallal/Search/index.html

If you download my super easy word merge, you'll also find that it has an
example search form that's similar to the above screen shots.

You can find that here:

The sample I have can be found here:
http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html
 
my code is as follows, the Command44 button doesn't start the filter, I have
to physically click the two toolbar buttons "filter by form" and then "apply
filter" to get it to work every time I open the program. This is a problem
as it needs to be something anyone in my company can just open and use
without knowing about this glitch. After I've clicked the two buttons on the
toolbar then my Command44 button works fine. any thoughts?

Private Sub Combo24_AfterUpdate()

End Sub

Private Sub Command44_Click()

Dim strWhere As String 'The criteria string.
Dim lngLen As Long

If Not IsNull(Me.Combo22) Then
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """) AND "
End If


If Not IsNull(Me.Combo24) Then
strWhere = strWhere & "([ICA] = """ & Me.Combo24 & """) AND "
End If

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
Debug.Print strWhere


Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub





Private Sub Command43_Click()
'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(acDetail).Controls
Select Case ctl.ControlType
Case acComboBox
ctl.Value = Null
End Select
Next

'Remove the form's filter.
Me.FilterOn = False
End Sub
 
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """) AND "

Is snm type a number type field, or text type field. (you have to check in
the table desing view to be sure). I also perfer the user of single quotes
as it bit less " plahing.

eg:

strWhere = strWhere & "([SNM TYPE] = '" & Me.Combo22 & "' AND "

Also, code is not quite right for if one of the combos is not set.

Try:

If Not IsNull(Me.Combo22) Then
strWhere = "([SNM TYPE] = '" & Me.Combo22 & "')"
End If

If Not IsNull(Me.Combo24) Then
if strWhere <> "" then
strWhere = strWhere & " and "
end if
strWhere = strWhere & "([ICA] = '" & Me.Combo24 & "')"
End If

if strWhere = "" then
MsgBox "No criteria, all data will show", vbInformation, "Nothing to do."
end if

debug.print strWhere
me.Filter = strwhere
me.FilterOn = true

Note how the 2nd conditaiton of code is desinged to "add" to the previoues
codndin. yOu cna contineu that same block of code for as many additonal
contorls onthe frm. And, if none of the ocntorls are filled..then stWhere
will = blank.
Also, after the above code runs, take a look at the debug.print of the
strWhere...does it look correct?

So, remember, if ica, or snm type are number fields, then your code looks
like:
strWhere = strWhere & "([ICA] = " & Me.Combo24 & ")"
 
Thanks Albert, they both are text fields. what did you mean when you said
"if one of the combos is not set" ?

Albert D. Kallal said:
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """) AND "

Is snm type a number type field, or text type field. (you have to check in
the table desing view to be sure). I also perfer the user of single quotes
as it bit less " plahing.

eg:

strWhere = strWhere & "([SNM TYPE] = '" & Me.Combo22 & "' AND "

Also, code is not quite right for if one of the combos is not set.

Try:

If Not IsNull(Me.Combo22) Then
strWhere = "([SNM TYPE] = '" & Me.Combo22 & "')"
End If

If Not IsNull(Me.Combo24) Then
if strWhere <> "" then
strWhere = strWhere & " and "
end if
strWhere = strWhere & "([ICA] = '" & Me.Combo24 & "')"
End If

if strWhere = "" then
MsgBox "No criteria, all data will show", vbInformation, "Nothing to do."
end if

debug.print strWhere
me.Filter = strwhere
me.FilterOn = true

Note how the 2nd conditaiton of code is desinged to "add" to the previoues
codndin. yOu cna contineu that same block of code for as many additonal
contorls onthe frm. And, if none of the ocntorls are filled..then stWhere
will = blank.
Also, after the above code runs, take a look at the debug.print of the
strWhere...does it look correct?

So, remember, if ica, or snm type are number fields, then your code looks
like:
strWhere = strWhere & "([ICA] = " & Me.Combo24 & ")"
 
Also, I tried using your code, and I still have to manually set the filters
with the toolbar buttons for it to work. Thanks anyways!

Albert D. Kallal said:
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """) AND "

Is snm type a number type field, or text type field. (you have to check in
the table desing view to be sure). I also perfer the user of single quotes
as it bit less " plahing.

eg:

strWhere = strWhere & "([SNM TYPE] = '" & Me.Combo22 & "' AND "

Also, code is not quite right for if one of the combos is not set.

Try:

If Not IsNull(Me.Combo22) Then
strWhere = "([SNM TYPE] = '" & Me.Combo22 & "')"
End If

If Not IsNull(Me.Combo24) Then
if strWhere <> "" then
strWhere = strWhere & " and "
end if
strWhere = strWhere & "([ICA] = '" & Me.Combo24 & "')"
End If

if strWhere = "" then
MsgBox "No criteria, all data will show", vbInformation, "Nothing to do."
end if

debug.print strWhere
me.Filter = strwhere
me.FilterOn = true

Note how the 2nd conditaiton of code is desinged to "add" to the previoues
codndin. yOu cna contineu that same block of code for as many additonal
contorls onthe frm. And, if none of the ocntorls are filled..then stWhere
will = blank.
Also, after the above code runs, take a look at the debug.print of the
strWhere...does it look correct?

So, remember, if ica, or snm type are number fields, then your code looks
like:
strWhere = strWhere & "([ICA] = " & Me.Combo24 & ")"
 
This is just some thoughts about newsgroup postings. In this thread you
asked a question, then without waiting for an answer proceeded to the
conclusion that the suggestion doesn't work. The comment that the code is
not right "if one of the combos is not set" probably means that if one of
the combo boxes is null or does not contain a valid item the code will not
work.

In another thread you responded to a suggestion with what strikes me as a
somewhat dismissive "I did what you said, and still no results, thank you
for trying." You have now apparently abandoned that thread. However, the
suggestion made in that thread by Douglas Steele will work, but you did not
respond to the request for further details. My suggestion in that thread
would have worked too, but again details about your database were missing.
If for whatever reason you choose not to follow through on a suggested
course of action that is your choice, but please do not hurry to the
conclusion that the problem is with the suggestion, especially if you do not
respond to requests for clarification.

For best results, be specific about error messages or the exact nature of
the failure. Responses such as "It did not work" are too vague.

NukeEng85 said:
Also, I tried using your code, and I still have to manually set the
filters
with the toolbar buttons for it to work. Thanks anyways!

Albert D. Kallal said:
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """)
AND "

Is snm type a number type field, or text type field. (you have to check
in
the table desing view to be sure). I also perfer the user of single
quotes
as it bit less " plahing.

eg:

strWhere = strWhere & "([SNM TYPE] = '" & Me.Combo22 & "' AND "

Also, code is not quite right for if one of the combos is not set.

Try:

If Not IsNull(Me.Combo22) Then
strWhere = "([SNM TYPE] = '" & Me.Combo22 & "')"
End If

If Not IsNull(Me.Combo24) Then
if strWhere <> "" then
strWhere = strWhere & " and "
end if
strWhere = strWhere & "([ICA] = '" & Me.Combo24 & "')"
End If

if strWhere = "" then
MsgBox "No criteria, all data will show", vbInformation, "Nothing to
do."
end if

debug.print strWhere
me.Filter = strwhere
me.FilterOn = true

Note how the 2nd conditaiton of code is desinged to "add" to the
previoues
codndin. yOu cna contineu that same block of code for as many additonal
contorls onthe frm. And, if none of the ocntorls are filled..then stWhere
will = blank.
Also, after the above code runs, take a look at the debug.print of the
strWhere...does it look correct?

So, remember, if ica, or snm type are number fields, then your code looks
like:
strWhere = strWhere & "([ICA] = " & Me.Combo24 & ")"
 
Bruce,

Thank you for your suggestion, I will try to be more clear with my responses
concerning problems I'm having with the codes. I actually have been
continuously checking all the threads I have started, and I tried what both
yourself and Douglas Steele suggested, and was still having problems. I have
since then figured out a different way to produce the same results, which is
why I didn't respond.

As far as providing more details, I'm not sure what other details people
need as I have posted the Macro code multiple times, and all of the event
builder and query information I have. If there is something I'm not
including I would really appreciate your input because I am trying to do what
I can to help the people who are being so kind as to help me. What should I
respond when I try something that someone suggests and I get no results? I'm
obviously not very in-tune with the posting etiquette, thank you for your
assistance.

BruceM said:
This is just some thoughts about newsgroup postings. In this thread you
asked a question, then without waiting for an answer proceeded to the
conclusion that the suggestion doesn't work. The comment that the code is
not right "if one of the combos is not set" probably means that if one of
the combo boxes is null or does not contain a valid item the code will not
work.

In another thread you responded to a suggestion with what strikes me as a
somewhat dismissive "I did what you said, and still no results, thank you
for trying." You have now apparently abandoned that thread. However, the
suggestion made in that thread by Douglas Steele will work, but you did not
respond to the request for further details. My suggestion in that thread
would have worked too, but again details about your database were missing.
If for whatever reason you choose not to follow through on a suggested
course of action that is your choice, but please do not hurry to the
conclusion that the problem is with the suggestion, especially if you do not
respond to requests for clarification.

For best results, be specific about error messages or the exact nature of
the failure. Responses such as "It did not work" are too vague.

NukeEng85 said:
Also, I tried using your code, and I still have to manually set the
filters
with the toolbar buttons for it to work. Thanks anyways!

Albert D. Kallal said:
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """)
AND "

Is snm type a number type field, or text type field. (you have to check
in
the table desing view to be sure). I also perfer the user of single
quotes
as it bit less " plahing.

eg:

strWhere = strWhere & "([SNM TYPE] = '" & Me.Combo22 & "' AND "

Also, code is not quite right for if one of the combos is not set.

Try:

If Not IsNull(Me.Combo22) Then
strWhere = "([SNM TYPE] = '" & Me.Combo22 & "')"
End If

If Not IsNull(Me.Combo24) Then
if strWhere <> "" then
strWhere = strWhere & " and "
end if
strWhere = strWhere & "([ICA] = '" & Me.Combo24 & "')"
End If

if strWhere = "" then
MsgBox "No criteria, all data will show", vbInformation, "Nothing to
do."
end if

debug.print strWhere
me.Filter = strwhere
me.FilterOn = true

Note how the 2nd conditaiton of code is desinged to "add" to the
previoues
codndin. yOu cna contineu that same block of code for as many additonal
contorls onthe frm. And, if none of the ocntorls are filled..then stWhere
will = blank.
Also, after the above code runs, take a look at the debug.print of the
strWhere...does it look correct?

So, remember, if ica, or snm type are number fields, then your code looks
like:
strWhere = strWhere & "([ICA] = " & Me.Combo24 & ")"
 
In another thread you posted what you idenitifed as After Update code. I
pointed out that there was no After Update code, so nothing would happen
when selecting from the combo box. A response from you would have shown
that you understand (or not) why selecting from the combo box could not
accomplish anything. You posted command button code that may work to filter
the records provided that both combo boxes contain a selection, and that
neither contains (All). However, you did not respond to my observation that
selecting (All) and clicking the command button will produce no results,
given the command botton code as posted. I also suggested that you verify
the string being produced by the code. The Debug.Print line of code would
have accomplished that.
These are the sorts of things to which I referred. Following the suggestion
to verify the filter string it would have been helpful to know if you had
done so and what you had discovered. That new information would have helped
narrow down the problem, which would have increased the chances of finding a
solution.
I'm not trying to take you to task for newsgroup etiquette, but rather
pointing out that a careful reading of and effort to implement posted
suggestions can lead to a solution. Even if you tried the suggestions, a
brief response that makes no mention of that is somewhat unlikely to draw
further responses and suggestions, at least no in depth.

NukeEng85 said:
Bruce,

Thank you for your suggestion, I will try to be more clear with my
responses
concerning problems I'm having with the codes. I actually have been
continuously checking all the threads I have started, and I tried what
both
yourself and Douglas Steele suggested, and was still having problems. I
have
since then figured out a different way to produce the same results, which
is
why I didn't respond.

As far as providing more details, I'm not sure what other details people
need as I have posted the Macro code multiple times, and all of the event
builder and query information I have. If there is something I'm not
including I would really appreciate your input because I am trying to do
what
I can to help the people who are being so kind as to help me. What should
I
respond when I try something that someone suggests and I get no results?
I'm
obviously not very in-tune with the posting etiquette, thank you for your
assistance.

BruceM said:
This is just some thoughts about newsgroup postings. In this thread you
asked a question, then without waiting for an answer proceeded to the
conclusion that the suggestion doesn't work. The comment that the code
is
not right "if one of the combos is not set" probably means that if one of
the combo boxes is null or does not contain a valid item the code will
not
work.

In another thread you responded to a suggestion with what strikes me as a
somewhat dismissive "I did what you said, and still no results, thank you
for trying." You have now apparently abandoned that thread. However,
the
suggestion made in that thread by Douglas Steele will work, but you did
not
respond to the request for further details. My suggestion in that thread
would have worked too, but again details about your database were
missing.
If for whatever reason you choose not to follow through on a suggested
course of action that is your choice, but please do not hurry to the
conclusion that the problem is with the suggestion, especially if you do
not
respond to requests for clarification.

For best results, be specific about error messages or the exact nature of
the failure. Responses such as "It did not work" are too vague.

NukeEng85 said:
Also, I tried using your code, and I still have to manually set the
filters
with the toolbar buttons for it to work. Thanks anyways!

:

strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """)
AND "

Is snm type a number type field, or text type field. (you have to
check
in
the table desing view to be sure). I also perfer the user of single
quotes
as it bit less " plahing.

eg:

strWhere = strWhere & "([SNM TYPE] = '" & Me.Combo22 & "' AND "

Also, code is not quite right for if one of the combos is not set.

Try:

If Not IsNull(Me.Combo22) Then
strWhere = "([SNM TYPE] = '" & Me.Combo22 & "')"
End If

If Not IsNull(Me.Combo24) Then
if strWhere <> "" then
strWhere = strWhere & " and "
end if
strWhere = strWhere & "([ICA] = '" & Me.Combo24 & "')"
End If

if strWhere = "" then
MsgBox "No criteria, all data will show", vbInformation, "Nothing
to
do."
end if

debug.print strWhere
me.Filter = strwhere
me.FilterOn = true

Note how the 2nd conditaiton of code is desinged to "add" to the
previoues
codndin. yOu cna contineu that same block of code for as many
additonal
contorls onthe frm. And, if none of the ocntorls are filled..then
stWhere
will = blank.
Also, after the above code runs, take a look at the debug.print of the
strWhere...does it look correct?

So, remember, if ica, or snm type are number fields, then your code
looks
like:
strWhere = strWhere & "([ICA] = " & Me.Combo24 & ")"
 
I think I may have just realized what happened. I thought the command button
code was what you were asking for in regards to the Debug.Print line code. I
did include what the "immediate window" gave me, I must not know how to
verify the string being produced by the code, I thought that's what I was
doing, my apologies!

BruceM said:
In another thread you posted what you idenitifed as After Update code. I
pointed out that there was no After Update code, so nothing would happen
when selecting from the combo box. A response from you would have shown
that you understand (or not) why selecting from the combo box could not
accomplish anything. You posted command button code that may work to filter
the records provided that both combo boxes contain a selection, and that
neither contains (All). However, you did not respond to my observation that
selecting (All) and clicking the command button will produce no results,
given the command botton code as posted. I also suggested that you verify
the string being produced by the code. The Debug.Print line of code would
have accomplished that.
These are the sorts of things to which I referred. Following the suggestion
to verify the filter string it would have been helpful to know if you had
done so and what you had discovered. That new information would have helped
narrow down the problem, which would have increased the chances of finding a
solution.
I'm not trying to take you to task for newsgroup etiquette, but rather
pointing out that a careful reading of and effort to implement posted
suggestions can lead to a solution. Even if you tried the suggestions, a
brief response that makes no mention of that is somewhat unlikely to draw
further responses and suggestions, at least no in depth.

NukeEng85 said:
Bruce,

Thank you for your suggestion, I will try to be more clear with my
responses
concerning problems I'm having with the codes. I actually have been
continuously checking all the threads I have started, and I tried what
both
yourself and Douglas Steele suggested, and was still having problems. I
have
since then figured out a different way to produce the same results, which
is
why I didn't respond.

As far as providing more details, I'm not sure what other details people
need as I have posted the Macro code multiple times, and all of the event
builder and query information I have. If there is something I'm not
including I would really appreciate your input because I am trying to do
what
I can to help the people who are being so kind as to help me. What should
I
respond when I try something that someone suggests and I get no results?
I'm
obviously not very in-tune with the posting etiquette, thank you for your
assistance.

BruceM said:
This is just some thoughts about newsgroup postings. In this thread you
asked a question, then without waiting for an answer proceeded to the
conclusion that the suggestion doesn't work. The comment that the code
is
not right "if one of the combos is not set" probably means that if one of
the combo boxes is null or does not contain a valid item the code will
not
work.

In another thread you responded to a suggestion with what strikes me as a
somewhat dismissive "I did what you said, and still no results, thank you
for trying." You have now apparently abandoned that thread. However,
the
suggestion made in that thread by Douglas Steele will work, but you did
not
respond to the request for further details. My suggestion in that thread
would have worked too, but again details about your database were
missing.
If for whatever reason you choose not to follow through on a suggested
course of action that is your choice, but please do not hurry to the
conclusion that the problem is with the suggestion, especially if you do
not
respond to requests for clarification.

For best results, be specific about error messages or the exact nature of
the failure. Responses such as "It did not work" are too vague.

Also, I tried using your code, and I still have to manually set the
filters
with the toolbar buttons for it to work. Thanks anyways!

:

strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """)
AND "

Is snm type a number type field, or text type field. (you have to
check
in
the table desing view to be sure). I also perfer the user of single
quotes
as it bit less " plahing.

eg:

strWhere = strWhere & "([SNM TYPE] = '" & Me.Combo22 & "' AND "

Also, code is not quite right for if one of the combos is not set.

Try:

If Not IsNull(Me.Combo22) Then
strWhere = "([SNM TYPE] = '" & Me.Combo22 & "')"
End If

If Not IsNull(Me.Combo24) Then
if strWhere <> "" then
strWhere = strWhere & " and "
end if
strWhere = strWhere & "([ICA] = '" & Me.Combo24 & "')"
End If

if strWhere = "" then
MsgBox "No criteria, all data will show", vbInformation, "Nothing
to
do."
end if

debug.print strWhere
me.Filter = strwhere
me.FilterOn = true

Note how the 2nd conditaiton of code is desinged to "add" to the
previoues
codndin. yOu cna contineu that same block of code for as many
additonal
contorls onthe frm. And, if none of the ocntorls are filled..then
stWhere
will = blank.
Also, after the above code runs, take a look at the debug.print of the
strWhere...does it look correct?

So, remember, if ica, or snm type are number fields, then your code
looks
like:
strWhere = strWhere & "([ICA] = " & Me.Combo24 & ")"
 
I did not see where you included what the immediate window gave you. It
took me a while to figure out Debug.Print. Just to be sure we are on the
same page, and with no attempt to offend if you are in fact familiar with
it, the way it works is this: After running the code (in the case of the
command button code in the other thread, by clicking the command button),
press Ctrl + G to open the VBA editor to the Immediate Window. There should
be a text string there along the lines of:
([SNM TYPE] = "SomeValidTextValue")

or

([SNM TYPE] = "(All)")

BTW, I don't see that the parentheses in the text strings are accomplishing
anything, and they may be hurting.

Anyhow, this is your filter string.

NukeEng85 said:
I think I may have just realized what happened. I thought the command
button
code was what you were asking for in regards to the Debug.Print line code.
I
did include what the "immediate window" gave me, I must not know how to
verify the string being produced by the code, I thought that's what I was
doing, my apologies!

BruceM said:
In another thread you posted what you idenitifed as After Update code. I
pointed out that there was no After Update code, so nothing would happen
when selecting from the combo box. A response from you would have shown
that you understand (or not) why selecting from the combo box could not
accomplish anything. You posted command button code that may work to
filter
the records provided that both combo boxes contain a selection, and that
neither contains (All). However, you did not respond to my observation
that
selecting (All) and clicking the command button will produce no results,
given the command botton code as posted. I also suggested that you
verify
the string being produced by the code. The Debug.Print line of code
would
have accomplished that.
These are the sorts of things to which I referred. Following the
suggestion
to verify the filter string it would have been helpful to know if you had
done so and what you had discovered. That new information would have
helped
narrow down the problem, which would have increased the chances of
finding a
solution.
I'm not trying to take you to task for newsgroup etiquette, but rather
pointing out that a careful reading of and effort to implement posted
suggestions can lead to a solution. Even if you tried the suggestions, a
brief response that makes no mention of that is somewhat unlikely to draw
further responses and suggestions, at least no in depth.

NukeEng85 said:
Bruce,

Thank you for your suggestion, I will try to be more clear with my
responses
concerning problems I'm having with the codes. I actually have been
continuously checking all the threads I have started, and I tried what
both
yourself and Douglas Steele suggested, and was still having problems.
I
have
since then figured out a different way to produce the same results,
which
is
why I didn't respond.

As far as providing more details, I'm not sure what other details
people
need as I have posted the Macro code multiple times, and all of the
event
builder and query information I have. If there is something I'm not
including I would really appreciate your input because I am trying to
do
what
I can to help the people who are being so kind as to help me. What
should
I
respond when I try something that someone suggests and I get no
results?
I'm
obviously not very in-tune with the posting etiquette, thank you for
your
assistance.

:

This is just some thoughts about newsgroup postings. In this thread
you
asked a question, then without waiting for an answer proceeded to the
conclusion that the suggestion doesn't work. The comment that the
code
is
not right "if one of the combos is not set" probably means that if one
of
the combo boxes is null or does not contain a valid item the code will
not
work.

In another thread you responded to a suggestion with what strikes me
as a
somewhat dismissive "I did what you said, and still no results, thank
you
for trying." You have now apparently abandoned that thread. However,
the
suggestion made in that thread by Douglas Steele will work, but you
did
not
respond to the request for further details. My suggestion in that
thread
would have worked too, but again details about your database were
missing.
If for whatever reason you choose not to follow through on a suggested
course of action that is your choice, but please do not hurry to the
conclusion that the problem is with the suggestion, especially if you
do
not
respond to requests for clarification.

For best results, be specific about error messages or the exact nature
of
the failure. Responses such as "It did not work" are too vague.

Also, I tried using your code, and I still have to manually set the
filters
with the toolbar buttons for it to work. Thanks anyways!

:

strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 &
""")
AND "

Is snm type a number type field, or text type field. (you have to
check
in
the table desing view to be sure). I also perfer the user of single
quotes
as it bit less " plahing.

eg:

strWhere = strWhere & "([SNM TYPE] = '" & Me.Combo22 & "' AND "

Also, code is not quite right for if one of the combos is not set.

Try:

If Not IsNull(Me.Combo22) Then
strWhere = "([SNM TYPE] = '" & Me.Combo22 & "')"
End If

If Not IsNull(Me.Combo24) Then
if strWhere <> "" then
strWhere = strWhere & " and "
end if
strWhere = strWhere & "([ICA] = '" & Me.Combo24 & "')"
End If

if strWhere = "" then
MsgBox "No criteria, all data will show", vbInformation,
"Nothing
to
do."
end if

debug.print strWhere
me.Filter = strwhere
me.FilterOn = true

Note how the 2nd conditaiton of code is desinged to "add" to the
previoues
codndin. yOu cna contineu that same block of code for as many
additonal
contorls onthe frm. And, if none of the ocntorls are filled..then
stWhere
will = blank.
Also, after the above code runs, take a look at the debug.print of
the
strWhere...does it look correct?

So, remember, if ica, or snm type are number fields, then your code
looks
like:
strWhere = strWhere & "([ICA] = " & Me.Combo24 & ")"
 
Back
Top