use multiple combo boxes to filter table, results displayed in sub

N

NukeEng85

I have a table with about 8 fields displaying information pertaining to 5
different types of equipment (ex: "equipment type"; "serial number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can search for a
specific piece of equipment based on equipment type, location, and date using
3 different combo boxes, and having the results displayed in a table in a
subform.

one initial problem I had was when I tried linking the combo box to the
"equipment type" field, but because there are reapeating entries (there are
only 5 different types, and they all repeat ex: LPRM, APRM, SRM, IRM, there
are about 20 LPRM, 10 APRM, etc) when I went to view my form and try the
combo box, the available options were LPRM repeated 20 times, etc.

I am very new to access and don't know how to link the combo box selection
to filter the subform data, especially if I'm typing in the values for the
combo box to choose from instead of linking them to a field on my table.

I JUST learned what a query is, if that gives you an idea of my Access
level. I am very competent in Excel, and have done some Macros and Visual
Basic before in Excel

I have Access 2003
 
A

Allen Browne

To remove the duplicates from your combo, add the word DISTINCT to the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the query's Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it works. It does
involve using VBA code to build a string. It will be similar to what you
have done in Excel, though the idea of Null might be new for you. (A field
is null if there's no value stored there.)
 
N

NukeEng85

Ok, so I have figured out how to change your code to work for my form, but I
don't know where to put the code. I've been trying to code things in the
Macros or Modules tabs, but your "search2000" example didn't have the code
stored there. Where do you enter code in Access?

Allen Browne said:
To remove the duplicates from your combo, add the word DISTINCT to the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the query's Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it works. It does
involve using VBA code to build a string. It will be similar to what you
have done in Excel, though the idea of Null might be new for you. (A field
is null if there's no value stored there.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

NukeEng85 said:
I have a table with about 8 fields displaying information pertaining to 5
different types of equipment (ex: "equipment type"; "serial number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can search for a
specific piece of equipment based on equipment type, location, and date
using
3 different combo boxes, and having the results displayed in a table in a
subform.

one initial problem I had was when I tried linking the combo box to the
"equipment type" field, but because there are reapeating entries (there
are
only 5 different types, and they all repeat ex: LPRM, APRM, SRM, IRM,
there
are about 20 LPRM, 10 APRM, etc) when I went to view my form and try the
combo box, the available options were LPRM repeated 20 times, etc.

I am very new to access and don't know how to link the combo box selection
to filter the subform data, especially if I'm typing in the values for the
combo box to choose from instead of linking them to a field on my table.

I JUST learned what a query is, if that gives you an idea of my Access
level. I am very competent in Excel, and have done some Macros and Visual
Basic before in Excel

I have Access 2003
 
A

Allen Browne

Open the form in design view.

Right-click on the command button, and choose Properties.

On the Event tab of the Properties box, the On Click property is set to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

NukeEng85 said:
Ok, so I have figured out how to change your code to work for my form, but
I
don't know where to put the code. I've been trying to code things in the
Macros or Modules tabs, but your "search2000" example didn't have the code
stored there. Where do you enter code in Access?

Allen Browne said:
To remove the duplicates from your combo, add the word DISTINCT to the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the query's
Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it works. It
does
involve using VBA code to build a string. It will be similar to what you
have done in Excel, though the idea of Null might be new for you. (A
field
is null if there's no value stored there.)

NukeEng85 said:
I have a table with about 8 fields displaying information pertaining to
5
different types of equipment (ex: "equipment type"; "serial number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can search for
a
specific piece of equipment based on equipment type, location, and date
using
3 different combo boxes, and having the results displayed in a table in
a
subform.

one initial problem I had was when I tried linking the combo box to the
"equipment type" field, but because there are reapeating entries (there
are
only 5 different types, and they all repeat ex: LPRM, APRM, SRM, IRM,
there
are about 20 LPRM, 10 APRM, etc) when I went to view my form and try
the
combo box, the available options were LPRM repeated 20 times, etc.

I am very new to access and don't know how to link the combo box
selection
to filter the subform data, especially if I'm typing in the values for
the
combo box to choose from instead of linking them to a field on my
table.

I JUST learned what a query is, if that gives you an idea of my Access
level. I am very competent in Excel, and have done some Macros and
Visual
Basic before in Excel

I have Access 2003
 
N

NukeEng85

I'm having problems with the buttons from your code, the ones to start the
filter and to reset the filter. I'm using your code is as follows:

Private Sub cmdReset_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(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.FilterOn = False
End Sub

What in the code do I need to change to fit my database? What does
"acheader" mean? does all this code got to one button? or do I need to make
two separate buttons?

Allen Browne said:
Open the form in design view.

Right-click on the command button, and choose Properties.

On the Event tab of the Properties box, the On Click property is set to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

NukeEng85 said:
Ok, so I have figured out how to change your code to work for my form, but
I
don't know where to put the code. I've been trying to code things in the
Macros or Modules tabs, but your "search2000" example didn't have the code
stored there. Where do you enter code in Access?

Allen Browne said:
To remove the duplicates from your combo, add the word DISTINCT to the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the query's
Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it works. It
does
involve using VBA code to build a string. It will be similar to what you
have done in Excel, though the idea of Null might be new for you. (A
field
is null if there's no value stored there.)

I have a table with about 8 fields displaying information pertaining to
5
different types of equipment (ex: "equipment type"; "serial number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can search for
a
specific piece of equipment based on equipment type, location, and date
using
3 different combo boxes, and having the results displayed in a table in
a
subform.

one initial problem I had was when I tried linking the combo box to the
"equipment type" field, but because there are reapeating entries (there
are
only 5 different types, and they all repeat ex: LPRM, APRM, SRM, IRM,
there
are about 20 LPRM, 10 APRM, etc) when I went to view my form and try
the
combo box, the available options were LPRM repeated 20 times, etc.

I am very new to access and don't know how to link the combo box
selection
to filter the subform data, especially if I'm typing in the values for
the
combo box to choose from instead of linking them to a field on my
table.

I JUST learned what a query is, if that gives you an idea of my Access
level. I am very competent in Excel, and have done some Macros and
Visual
Basic before in Excel

I have Access 2003
 
N

NukeEng85

This is the code I have, the Command44 button is the "go" button which should
run the filter, when I come out of design view, select from my cbo and push
it nothing happens

The reset button works though!

Any thoughts?

Option Compare Database

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 & """) "
End If


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

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

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




Allen Browne said:
Open the form in design view.

Right-click on the command button, and choose Properties.

On the Event tab of the Properties box, the On Click property is set to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

NukeEng85 said:
Ok, so I have figured out how to change your code to work for my form, but
I
don't know where to put the code. I've been trying to code things in the
Macros or Modules tabs, but your "search2000" example didn't have the code
stored there. Where do you enter code in Access?

Allen Browne said:
To remove the duplicates from your combo, add the word DISTINCT to the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the query's
Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it works. It
does
involve using VBA code to build a string. It will be similar to what you
have done in Excel, though the idea of Null might be new for you. (A
field
is null if there's no value stored there.)

I have a table with about 8 fields displaying information pertaining to
5
different types of equipment (ex: "equipment type"; "serial number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can search for
a
specific piece of equipment based on equipment type, location, and date
using
3 different combo boxes, and having the results displayed in a table in
a
subform.

one initial problem I had was when I tried linking the combo box to the
"equipment type" field, but because there are reapeating entries (there
are
only 5 different types, and they all repeat ex: LPRM, APRM, SRM, IRM,
there
are about 20 LPRM, 10 APRM, etc) when I went to view my form and try
the
combo box, the available options were LPRM repeated 20 times, etc.

I am very new to access and don't know how to link the combo box
selection
to filter the subform data, especially if I'm typing in the values for
the
combo box to choose from instead of linking them to a field on my
table.

I JUST learned what a query is, if that gives you an idea of my Access
level. I am very competent in Excel, and have done some Macros and
Visual
Basic before in Excel

I have Access 2003
 
A

Allen Browne

You are missing the AND at the end of each line that sets strWhere, e.g.:
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """) AND "

Just above the "Me.Filter = strWhere" line, add:
Debug.Print strWhere
Stop

When it runs, open the Immediate Window (Ctrl+G.)
Look at what comes out, and see if it is right.
Press F8 To single-step through the rest of the procedure until it ends.

Also, to ensure the code is correct, take these steps in the code window:
1. Choose Compile on the Debug menu.

2. Make sure you have this line at the very top of the code module:
Option Explicit

3. Under Tools | Options (in the code window), on the General tab, set Error
Trapping to 'Break on nhandled Errors', and uncheck the box 'Compile on
Demand.'

If you are still stuck, post what comes out of the Debug.Print, and tell us
what type of field you have in your table (in design view) for SNM_TYPE and
ICA.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

NukeEng85 said:
This is the code I have, the Command44 button is the "go" button which
should
run the filter, when I come out of design view, select from my cbo and
push
it nothing happens

The reset button works though!

Any thoughts?

Option Compare Database

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 & """) "
End If


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

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

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




Allen Browne said:
Open the form in design view.

Right-click on the command button, and choose Properties.

On the Event tab of the Properties box, the On Click property is set to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

NukeEng85 said:
Ok, so I have figured out how to change your code to work for my form,
but
I
don't know where to put the code. I've been trying to code things in
the
Macros or Modules tabs, but your "search2000" example didn't have the
code
stored there. Where do you enter code in Access?

:

To remove the duplicates from your combo, add the word DISTINCT to the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the query's
Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it works. It
does
involve using VBA code to build a string. It will be similar to what
you
have done in Excel, though the idea of Null might be new for you. (A
field
is null if there's no value stored there.)

I have a table with about 8 fields displaying information pertaining
to
5
different types of equipment (ex: "equipment type"; "serial number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can search
for
a
specific piece of equipment based on equipment type, location, and
date
using
3 different combo boxes, and having the results displayed in a table
in
a
subform.

one initial problem I had was when I tried linking the combo box to
the
"equipment type" field, but because there are reapeating entries
(there
are
only 5 different types, and they all repeat ex: LPRM, APRM, SRM,
IRM,
there
are about 20 LPRM, 10 APRM, etc) when I went to view my form and try
the
combo box, the available options were LPRM repeated 20 times, etc.

I am very new to access and don't know how to link the combo box
selection
to filter the subform data, especially if I'm typing in the values
for
the
combo box to choose from instead of linking them to a field on my
table.

I JUST learned what a query is, if that gives you an idea of my
Access
level. I am very competent in Excel, and have done some Macros and
Visual
Basic before in Excel

I have Access 2003
 
N

NukeEng85

I added the "AND" and did all the other steps you suggested, and it still
isn't working when I push the command44 button (the Go button)
This is what comes up in the "immediate" box:

([SNM TYPE] = "LPRM") AND([ICA] = "Reactor Core"

It seems to be correct, SNM TYPE and ICA are my fields that the combo boxes
select from, and "LPRM" and "Reactor Core" are the choices I selected from
the drop down box. The Form still works and pulls up filtered results if I
select what I want, save it, go into Design view, and then exit Design view
and go back to the normal view, but the Command44 button just doesn't seem to
work.
My code for the Go button is below, Is what was in the immediate window what
you wanted for the debug.print? I'm not sure what you mean regarding what
type of fields I have, maybe just that the data types are both "text"? I
don't know if this will help, but both my combo boxes are unbound, have
"table/query" for the rowsourcetype, and this for the rowsource: SELECT
DISTINCT [SNM Data].[SNM Type] FROM [SNM Data] ORDER BY [SNM Type]; where SNM
Data is my table and SNM Type is the field. The other Combo box has the
other field name of course.

Option Compare Database
Option Explicit



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
Stop

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


Thank you so much for all your help! It is very much appreciated.


Allen Browne said:
You are missing the AND at the end of each line that sets strWhere, e.g.:
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """) AND "

Just above the "Me.Filter = strWhere" line, add:
Debug.Print strWhere
Stop

When it runs, open the Immediate Window (Ctrl+G.)
Look at what comes out, and see if it is right.
Press F8 To single-step through the rest of the procedure until it ends.

Also, to ensure the code is correct, take these steps in the code window:
1. Choose Compile on the Debug menu.

2. Make sure you have this line at the very top of the code module:
Option Explicit

3. Under Tools | Options (in the code window), on the General tab, set Error
Trapping to 'Break on nhandled Errors', and uncheck the box 'Compile on
Demand.'

If you are still stuck, post what comes out of the Debug.Print, and tell us
what type of field you have in your table (in design view) for SNM_TYPE and
ICA.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

NukeEng85 said:
This is the code I have, the Command44 button is the "go" button which
should
run the filter, when I come out of design view, select from my cbo and
push
it nothing happens

The reset button works though!

Any thoughts?

Option Compare Database

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 & """) "
End If


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

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

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




Allen Browne said:
Open the form in design view.

Right-click on the command button, and choose Properties.

On the Event tab of the Properties box, the On Click property is set to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Ok, so I have figured out how to change your code to work for my form,
but
I
don't know where to put the code. I've been trying to code things in
the
Macros or Modules tabs, but your "search2000" example didn't have the
code
stored there. Where do you enter code in Access?

:

To remove the duplicates from your combo, add the word DISTINCT to the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the query's
Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it works. It
does
involve using VBA code to build a string. It will be similar to what
you
have done in Excel, though the idea of Null might be new for you. (A
field
is null if there's no value stored there.)

I have a table with about 8 fields displaying information pertaining
to
5
different types of equipment (ex: "equipment type"; "serial number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can search
for
a
specific piece of equipment based on equipment type, location, and
date
using
3 different combo boxes, and having the results displayed in a table
in
a
subform.

one initial problem I had was when I tried linking the combo box to
the
"equipment type" field, but because there are reapeating entries
(there
are
only 5 different types, and they all repeat ex: LPRM, APRM, SRM,
IRM,
there
are about 20 LPRM, 10 APRM, etc) when I went to view my form and try
the
combo box, the available options were LPRM repeated 20 times, etc.

I am very new to access and don't know how to link the combo box
selection
to filter the subform data, especially if I'm typing in the values
for
the
combo box to choose from instead of linking them to a field on my
table.

I JUST learned what a query is, if that gives you an idea of my
Access
level. I am very competent in Excel, and have done some Macros and
Visual
Basic before in Excel

I have Access 2003
 
D

Douglas J. Steele

You're only adding four characters (" AND"), but you're removing five, which
is why you're missing the closing parenthesis.

Add " AND " instead.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


NukeEng85 said:
I added the "AND" and did all the other steps you suggested, and it still
isn't working when I push the command44 button (the Go button)
This is what comes up in the "immediate" box:

([SNM TYPE] = "LPRM") AND([ICA] = "Reactor Core"

It seems to be correct, SNM TYPE and ICA are my fields that the combo
boxes
select from, and "LPRM" and "Reactor Core" are the choices I selected from
the drop down box. The Form still works and pulls up filtered results if
I
select what I want, save it, go into Design view, and then exit Design
view
and go back to the normal view, but the Command44 button just doesn't seem
to
work.
My code for the Go button is below, Is what was in the immediate window
what
you wanted for the debug.print? I'm not sure what you mean regarding what
type of fields I have, maybe just that the data types are both "text"? I
don't know if this will help, but both my combo boxes are unbound, have
"table/query" for the rowsourcetype, and this for the rowsource: SELECT
DISTINCT [SNM Data].[SNM Type] FROM [SNM Data] ORDER BY [SNM Type]; where
SNM
Data is my table and SNM Type is the field. The other Combo box has the
other field name of course.

Option Compare Database
Option Explicit



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
Stop

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


Thank you so much for all your help! It is very much appreciated.


Allen Browne said:
You are missing the AND at the end of each line that sets strWhere, e.g.:
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """) AND "

Just above the "Me.Filter = strWhere" line, add:
Debug.Print strWhere
Stop

When it runs, open the Immediate Window (Ctrl+G.)
Look at what comes out, and see if it is right.
Press F8 To single-step through the rest of the procedure until it ends.

Also, to ensure the code is correct, take these steps in the code window:
1. Choose Compile on the Debug menu.

2. Make sure you have this line at the very top of the code module:
Option Explicit

3. Under Tools | Options (in the code window), on the General tab, set
Error
Trapping to 'Break on nhandled Errors', and uncheck the box 'Compile on
Demand.'

If you are still stuck, post what comes out of the Debug.Print, and tell
us
what type of field you have in your table (in design view) for SNM_TYPE
and
ICA.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

NukeEng85 said:
This is the code I have, the Command44 button is the "go" button which
should
run the filter, when I come out of design view, select from my cbo and
push
it nothing happens

The reset button works though!

Any thoughts?

Option Compare Database

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 & """) "
End If


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

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

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




:

Open the form in design view.

Right-click on the command button, and choose Properties.

On the Event tab of the Properties box, the On Click property is set
to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Ok, so I have figured out how to change your code to work for my
form,
but
I
don't know where to put the code. I've been trying to code things
in
the
Macros or Modules tabs, but your "search2000" example didn't have
the
code
stored there. Where do you enter code in Access?

:

To remove the duplicates from your combo, add the word DISTINCT to
the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the query's
Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it works.
It
does
involve using VBA code to build a string. It will be similar to
what
you
have done in Excel, though the idea of Null might be new for you.
(A
field
is null if there's no value stored there.)

I have a table with about 8 fields displaying information
pertaining
to
5
different types of equipment (ex: "equipment type"; "serial
number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can
search
for
a
specific piece of equipment based on equipment type, location,
and
date
using
3 different combo boxes, and having the results displayed in a
table
in
a
subform.

one initial problem I had was when I tried linking the combo box
to
the
"equipment type" field, but because there are reapeating entries
(there
are
only 5 different types, and they all repeat ex: LPRM, APRM, SRM,
IRM,
there
are about 20 LPRM, 10 APRM, etc) when I went to view my form and
try
the
combo box, the available options were LPRM repeated 20 times,
etc.

I am very new to access and don't know how to link the combo box
selection
to filter the subform data, especially if I'm typing in the
values
for
the
combo box to choose from instead of linking them to a field on my
table.

I JUST learned what a query is, if that gives you an idea of my
Access
level. I am very competent in Excel, and have done some Macros
and
Visual
Basic before in Excel

I have Access 2003
 
N

NukeEng85

Thanks Douglas, I added the space and now the parenthesis is included, but
the button still doesn't work

Douglas J. Steele said:
You're only adding four characters (" AND"), but you're removing five, which
is why you're missing the closing parenthesis.

Add " AND " instead.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


NukeEng85 said:
I added the "AND" and did all the other steps you suggested, and it still
isn't working when I push the command44 button (the Go button)
This is what comes up in the "immediate" box:

([SNM TYPE] = "LPRM") AND([ICA] = "Reactor Core"

It seems to be correct, SNM TYPE and ICA are my fields that the combo
boxes
select from, and "LPRM" and "Reactor Core" are the choices I selected from
the drop down box. The Form still works and pulls up filtered results if
I
select what I want, save it, go into Design view, and then exit Design
view
and go back to the normal view, but the Command44 button just doesn't seem
to
work.
My code for the Go button is below, Is what was in the immediate window
what
you wanted for the debug.print? I'm not sure what you mean regarding what
type of fields I have, maybe just that the data types are both "text"? I
don't know if this will help, but both my combo boxes are unbound, have
"table/query" for the rowsourcetype, and this for the rowsource: SELECT
DISTINCT [SNM Data].[SNM Type] FROM [SNM Data] ORDER BY [SNM Type]; where
SNM
Data is my table and SNM Type is the field. The other Combo box has the
other field name of course.

Option Compare Database
Option Explicit



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
Stop

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


Thank you so much for all your help! It is very much appreciated.


Allen Browne said:
You are missing the AND at the end of each line that sets strWhere, e.g.:
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """) AND "

Just above the "Me.Filter = strWhere" line, add:
Debug.Print strWhere
Stop

When it runs, open the Immediate Window (Ctrl+G.)
Look at what comes out, and see if it is right.
Press F8 To single-step through the rest of the procedure until it ends.

Also, to ensure the code is correct, take these steps in the code window:
1. Choose Compile on the Debug menu.

2. Make sure you have this line at the very top of the code module:
Option Explicit

3. Under Tools | Options (in the code window), on the General tab, set
Error
Trapping to 'Break on nhandled Errors', and uncheck the box 'Compile on
Demand.'

If you are still stuck, post what comes out of the Debug.Print, and tell
us
what type of field you have in your table (in design view) for SNM_TYPE
and
ICA.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

This is the code I have, the Command44 button is the "go" button which
should
run the filter, when I come out of design view, select from my cbo and
push
it nothing happens

The reset button works though!

Any thoughts?

Option Compare Database

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 & """) "
End If


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

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

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




:

Open the form in design view.

Right-click on the command button, and choose Properties.

On the Event tab of the Properties box, the On Click property is set
to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Ok, so I have figured out how to change your code to work for my
form,
but
I
don't know where to put the code. I've been trying to code things
in
the
Macros or Modules tabs, but your "search2000" example didn't have
the
code
stored there. Where do you enter code in Access?

:

To remove the duplicates from your combo, add the word DISTINCT to
the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the query's
Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it works.
It
does
involve using VBA code to build a string. It will be similar to
what
you
have done in Excel, though the idea of Null might be new for you.
(A
field
is null if there's no value stored there.)

I have a table with about 8 fields displaying information
pertaining
to
5
different types of equipment (ex: "equipment type"; "serial
number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can
search
for
a
specific piece of equipment based on equipment type, location,
and
date
using
3 different combo boxes, and having the results displayed in a
table
in
a
subform.

one initial problem I had was when I tried linking the combo box
to
the
"equipment type" field, but because there are reapeating entries
(there
are
only 5 different types, and they all repeat ex: LPRM, APRM, SRM,
IRM,
there
are about 20 LPRM, 10 APRM, etc) when I went to view my form and
try
the
combo box, the available options were LPRM repeated 20 times,
etc.

I am very new to access and don't know how to link the combo box
selection
to filter the subform data, especially if I'm typing in the
values
for
the
combo box to choose from instead of linking them to a field on my
table.

I JUST learned what a query is, if that gives you an idea of my
Access
level. I am very competent in Excel, and have done some Macros
and
Visual
Basic before in Excel

I have Access 2003
 
D

Douglas J. Steele

Presumably you removed the Stop statement...

Incidentally, using Stop is seldom a good idea, as it doesn't do any cleanup
after itself.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


NukeEng85 said:
Thanks Douglas, I added the space and now the parenthesis is included, but
the button still doesn't work

Douglas J. Steele said:
You're only adding four characters (" AND"), but you're removing five,
which
is why you're missing the closing parenthesis.

Add " AND " instead.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


NukeEng85 said:
I added the "AND" and did all the other steps you suggested, and it
still
isn't working when I push the command44 button (the Go button)
This is what comes up in the "immediate" box:

([SNM TYPE] = "LPRM") AND([ICA] = "Reactor Core"

It seems to be correct, SNM TYPE and ICA are my fields that the combo
boxes
select from, and "LPRM" and "Reactor Core" are the choices I selected
from
the drop down box. The Form still works and pulls up filtered results
if
I
select what I want, save it, go into Design view, and then exit Design
view
and go back to the normal view, but the Command44 button just doesn't
seem
to
work.
My code for the Go button is below, Is what was in the immediate window
what
you wanted for the debug.print? I'm not sure what you mean regarding
what
type of fields I have, maybe just that the data types are both "text"?
I
don't know if this will help, but both my combo boxes are unbound, have
"table/query" for the rowsourcetype, and this for the rowsource: SELECT
DISTINCT [SNM Data].[SNM Type] FROM [SNM Data] ORDER BY [SNM Type];
where
SNM
Data is my table and SNM Type is the field. The other Combo box has
the
other field name of course.

Option Compare Database
Option Explicit



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
Stop

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


Thank you so much for all your help! It is very much appreciated.


:

You are missing the AND at the end of each line that sets strWhere,
e.g.:
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """) AND "

Just above the "Me.Filter = strWhere" line, add:
Debug.Print strWhere
Stop

When it runs, open the Immediate Window (Ctrl+G.)
Look at what comes out, and see if it is right.
Press F8 To single-step through the rest of the procedure until it
ends.

Also, to ensure the code is correct, take these steps in the code
window:
1. Choose Compile on the Debug menu.

2. Make sure you have this line at the very top of the code module:
Option Explicit

3. Under Tools | Options (in the code window), on the General tab, set
Error
Trapping to 'Break on nhandled Errors', and uncheck the box 'Compile
on
Demand.'

If you are still stuck, post what comes out of the Debug.Print, and
tell
us
what type of field you have in your table (in design view) for
SNM_TYPE
and
ICA.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

This is the code I have, the Command44 button is the "go" button
which
should
run the filter, when I come out of design view, select from my cbo
and
push
it nothing happens

The reset button works though!

Any thoughts?

Option Compare Database

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 & """)
"
End If


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

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

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




:

Open the form in design view.

Right-click on the command button, and choose Properties.

On the Event tab of the Properties box, the On Click property is
set
to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Ok, so I have figured out how to change your code to work for my
form,
but
I
don't know where to put the code. I've been trying to code
things
in
the
Macros or Modules tabs, but your "search2000" example didn't have
the
code
stored there. Where do you enter code in Access?

:

To remove the duplicates from your combo, add the word DISTINCT
to
the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the
query's
Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it
works.
It
does
involve using VBA code to build a string. It will be similar to
what
you
have done in Excel, though the idea of Null might be new for
you.
(A
field
is null if there's no value stored there.)

message
I have a table with about 8 fields displaying information
pertaining
to
5
different types of equipment (ex: "equipment type"; "serial
number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can
search
for
a
specific piece of equipment based on equipment type, location,
and
date
using
3 different combo boxes, and having the results displayed in a
table
in
a
subform.

one initial problem I had was when I tried linking the combo
box
to
the
"equipment type" field, but because there are reapeating
entries
(there
are
only 5 different types, and they all repeat ex: LPRM, APRM,
SRM,
IRM,
there
are about 20 LPRM, 10 APRM, etc) when I went to view my form
and
try
the
combo box, the available options were LPRM repeated 20 times,
etc.

I am very new to access and don't know how to link the combo
box
selection
to filter the subform data, especially if I'm typing in the
values
for
the
combo box to choose from instead of linking them to a field on
my
table.

I JUST learned what a query is, if that gives you an idea of
my
Access
level. I am very competent in Excel, and have done some
Macros
and
Visual
Basic before in Excel

I have Access 2003
 
N

NukeEng85

Yes, I did remove the stop statement, I was just using it to get a
debug.print.

When I'm in the non-design view and trying to run my form, I select what I
want from the combo boxes, click the "go" or command44 button and nothing
happens. However, I also have a reset button, and that one works to clear
out the Combo boxes. If I select my options, save it, click in and then back
out of Design view, then my form has automatically updated and the results
based on my selection are shown in the subform like they are supposed to. I
just can't get the button to do it.

Douglas J. Steele said:
Presumably you removed the Stop statement...

Incidentally, using Stop is seldom a good idea, as it doesn't do any cleanup
after itself.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


NukeEng85 said:
Thanks Douglas, I added the space and now the parenthesis is included, but
the button still doesn't work

Douglas J. Steele said:
You're only adding four characters (" AND"), but you're removing five,
which
is why you're missing the closing parenthesis.

Add " AND " instead.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I added the "AND" and did all the other steps you suggested, and it
still
isn't working when I push the command44 button (the Go button)
This is what comes up in the "immediate" box:

([SNM TYPE] = "LPRM") AND([ICA] = "Reactor Core"

It seems to be correct, SNM TYPE and ICA are my fields that the combo
boxes
select from, and "LPRM" and "Reactor Core" are the choices I selected
from
the drop down box. The Form still works and pulls up filtered results
if
I
select what I want, save it, go into Design view, and then exit Design
view
and go back to the normal view, but the Command44 button just doesn't
seem
to
work.
My code for the Go button is below, Is what was in the immediate window
what
you wanted for the debug.print? I'm not sure what you mean regarding
what
type of fields I have, maybe just that the data types are both "text"?
I
don't know if this will help, but both my combo boxes are unbound, have
"table/query" for the rowsourcetype, and this for the rowsource: SELECT
DISTINCT [SNM Data].[SNM Type] FROM [SNM Data] ORDER BY [SNM Type];
where
SNM
Data is my table and SNM Type is the field. The other Combo box has
the
other field name of course.

Option Compare Database
Option Explicit



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
Stop

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


Thank you so much for all your help! It is very much appreciated.


:

You are missing the AND at the end of each line that sets strWhere,
e.g.:
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """) AND "

Just above the "Me.Filter = strWhere" line, add:
Debug.Print strWhere
Stop

When it runs, open the Immediate Window (Ctrl+G.)
Look at what comes out, and see if it is right.
Press F8 To single-step through the rest of the procedure until it
ends.

Also, to ensure the code is correct, take these steps in the code
window:
1. Choose Compile on the Debug menu.

2. Make sure you have this line at the very top of the code module:
Option Explicit

3. Under Tools | Options (in the code window), on the General tab, set
Error
Trapping to 'Break on nhandled Errors', and uncheck the box 'Compile
on
Demand.'

If you are still stuck, post what comes out of the Debug.Print, and
tell
us
what type of field you have in your table (in design view) for
SNM_TYPE
and
ICA.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

This is the code I have, the Command44 button is the "go" button
which
should
run the filter, when I come out of design view, select from my cbo
and
push
it nothing happens

The reset button works though!

Any thoughts?

Option Compare Database

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 & """)
"
End If


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

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

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




:

Open the form in design view.

Right-click on the command button, and choose Properties.

On the Event tab of the Properties box, the On Click property is
set
to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Ok, so I have figured out how to change your code to work for my
form,
but
I
don't know where to put the code. I've been trying to code
things
in
the
Macros or Modules tabs, but your "search2000" example didn't have
the
code
stored there. Where do you enter code in Access?

:

To remove the duplicates from your combo, add the word DISTINCT
to
the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the
query's
Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it
works.
It
does
involve using VBA code to build a string. It will be similar to
what
you
have done in Excel, though the idea of Null might be new for
you.
(A
field
is null if there's no value stored there.)

message
I have a table with about 8 fields displaying information
pertaining
to
5
different types of equipment (ex: "equipment type"; "serial
number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can
search
for
a
specific piece of equipment based on equipment type, location,
and
date
using
3 different combo boxes, and having the results displayed in a
table
in
 
N

NukeEng85

So I'm not sure what I did, but it works, so thank you everyone!!!

Douglas J. Steele said:
Presumably you removed the Stop statement...

Incidentally, using Stop is seldom a good idea, as it doesn't do any cleanup
after itself.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


NukeEng85 said:
Thanks Douglas, I added the space and now the parenthesis is included, but
the button still doesn't work

Douglas J. Steele said:
You're only adding four characters (" AND"), but you're removing five,
which
is why you're missing the closing parenthesis.

Add " AND " instead.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I added the "AND" and did all the other steps you suggested, and it
still
isn't working when I push the command44 button (the Go button)
This is what comes up in the "immediate" box:

([SNM TYPE] = "LPRM") AND([ICA] = "Reactor Core"

It seems to be correct, SNM TYPE and ICA are my fields that the combo
boxes
select from, and "LPRM" and "Reactor Core" are the choices I selected
from
the drop down box. The Form still works and pulls up filtered results
if
I
select what I want, save it, go into Design view, and then exit Design
view
and go back to the normal view, but the Command44 button just doesn't
seem
to
work.
My code for the Go button is below, Is what was in the immediate window
what
you wanted for the debug.print? I'm not sure what you mean regarding
what
type of fields I have, maybe just that the data types are both "text"?
I
don't know if this will help, but both my combo boxes are unbound, have
"table/query" for the rowsourcetype, and this for the rowsource: SELECT
DISTINCT [SNM Data].[SNM Type] FROM [SNM Data] ORDER BY [SNM Type];
where
SNM
Data is my table and SNM Type is the field. The other Combo box has
the
other field name of course.

Option Compare Database
Option Explicit



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
Stop

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


Thank you so much for all your help! It is very much appreciated.


:

You are missing the AND at the end of each line that sets strWhere,
e.g.:
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """) AND "

Just above the "Me.Filter = strWhere" line, add:
Debug.Print strWhere
Stop

When it runs, open the Immediate Window (Ctrl+G.)
Look at what comes out, and see if it is right.
Press F8 To single-step through the rest of the procedure until it
ends.

Also, to ensure the code is correct, take these steps in the code
window:
1. Choose Compile on the Debug menu.

2. Make sure you have this line at the very top of the code module:
Option Explicit

3. Under Tools | Options (in the code window), on the General tab, set
Error
Trapping to 'Break on nhandled Errors', and uncheck the box 'Compile
on
Demand.'

If you are still stuck, post what comes out of the Debug.Print, and
tell
us
what type of field you have in your table (in design view) for
SNM_TYPE
and
ICA.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

This is the code I have, the Command44 button is the "go" button
which
should
run the filter, when I come out of design view, select from my cbo
and
push
it nothing happens

The reset button works though!

Any thoughts?

Option Compare Database

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 & """)
"
End If


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

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

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




:

Open the form in design view.

Right-click on the command button, and choose Properties.

On the Event tab of the Properties box, the On Click property is
set
to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Ok, so I have figured out how to change your code to work for my
form,
but
I
don't know where to put the code. I've been trying to code
things
in
the
Macros or Modules tabs, but your "search2000" example didn't have
the
code
stored there. Where do you enter code in Access?

:

To remove the duplicates from your combo, add the word DISTINCT
to
the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the
query's
Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it
works.
It
does
involve using VBA code to build a string. It will be similar to
what
you
have done in Excel, though the idea of Null might be new for
you.
(A
field
is null if there's no value stored there.)

message
I have a table with about 8 fields displaying information
pertaining
to
5
different types of equipment (ex: "equipment type"; "serial
number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can
search
for
a
specific piece of equipment based on equipment type, location,
and
date
using
3 different combo boxes, and having the results displayed in a
table
in
 
N

NukeEng85

ok, so I don't know what I did, but it worked for a few seconds, and then I
went into Design view to change the background color, came back to form view,
and it stopped working...

NukeEng85 said:
So I'm not sure what I did, but it works, so thank you everyone!!!

Douglas J. Steele said:
Presumably you removed the Stop statement...

Incidentally, using Stop is seldom a good idea, as it doesn't do any cleanup
after itself.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


NukeEng85 said:
Thanks Douglas, I added the space and now the parenthesis is included, but
the button still doesn't work

:

You're only adding four characters (" AND"), but you're removing five,
which
is why you're missing the closing parenthesis.

Add " AND " instead.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I added the "AND" and did all the other steps you suggested, and it
still
isn't working when I push the command44 button (the Go button)
This is what comes up in the "immediate" box:

([SNM TYPE] = "LPRM") AND([ICA] = "Reactor Core"

It seems to be correct, SNM TYPE and ICA are my fields that the combo
boxes
select from, and "LPRM" and "Reactor Core" are the choices I selected
from
the drop down box. The Form still works and pulls up filtered results
if
I
select what I want, save it, go into Design view, and then exit Design
view
and go back to the normal view, but the Command44 button just doesn't
seem
to
work.
My code for the Go button is below, Is what was in the immediate window
what
you wanted for the debug.print? I'm not sure what you mean regarding
what
type of fields I have, maybe just that the data types are both "text"?
I
don't know if this will help, but both my combo boxes are unbound, have
"table/query" for the rowsourcetype, and this for the rowsource: SELECT
DISTINCT [SNM Data].[SNM Type] FROM [SNM Data] ORDER BY [SNM Type];
where
SNM
Data is my table and SNM Type is the field. The other Combo box has
the
other field name of course.

Option Compare Database
Option Explicit



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
Stop

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


Thank you so much for all your help! It is very much appreciated.


:

You are missing the AND at the end of each line that sets strWhere,
e.g.:
strWhere = strWhere & "([SNM TYPE] = """ & Me.Combo22 & """) AND "

Just above the "Me.Filter = strWhere" line, add:
Debug.Print strWhere
Stop

When it runs, open the Immediate Window (Ctrl+G.)
Look at what comes out, and see if it is right.
Press F8 To single-step through the rest of the procedure until it
ends.

Also, to ensure the code is correct, take these steps in the code
window:
1. Choose Compile on the Debug menu.

2. Make sure you have this line at the very top of the code module:
Option Explicit

3. Under Tools | Options (in the code window), on the General tab, set
Error
Trapping to 'Break on nhandled Errors', and uncheck the box 'Compile
on
Demand.'

If you are still stuck, post what comes out of the Debug.Print, and
tell
us
what type of field you have in your table (in design view) for
SNM_TYPE
and
ICA.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

This is the code I have, the Command44 button is the "go" button
which
should
run the filter, when I come out of design view, select from my cbo
and
push
it nothing happens

The reset button works though!

Any thoughts?

Option Compare Database

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 & """)
"
End If


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

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

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




:

Open the form in design view.

Right-click on the command button, and choose Properties.

On the Event tab of the Properties box, the On Click property is
set
to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Ok, so I have figured out how to change your code to work for my
form,
but
I
don't know where to put the code. I've been trying to code
things
in
the
Macros or Modules tabs, but your "search2000" example didn't have
the
code
stored there. Where do you enter code in Access?

:

To remove the duplicates from your combo, add the word DISTINCT
to
the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the
query's
Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it
works.
It
does
involve using VBA code to build a string. It will be similar to
what
you
have done in Excel, though the idea of Null might be new for
you.
(A
field
is null if there's no value stored there.)

message
I have a table with about 8 fields displaying information
pertaining
to
5
different types of equipment (ex: "equipment type"; "serial
number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can
search
for
a
specific piece of equipment based on equipment type, location,
and
date
 
N

NukeEng85

To get it to work, you have to apply a filter to the subform, I thought that
the filter line in the code did that, but I right clicked the subform and
selected "apply filter/sort" and then it showed my selections in the combo
boxes, and if I selected something new and clicked "go", it showed my new
selections

Allen Browne said:
To remove the duplicates from your combo, add the word DISTINCT to the
RowSource.

The combo's RowSource property will probably be a query such as:
SELECT [MyField] FROM [MyTable] ORDER BY [MyField];
Change it like this

SELECT DISTINCT [MyField] FROM [MyTable] ORDER BY [MyField];
If you are doing this in query design view, you can set the query's Unique
Value property to Yes (in the Properties box.)

For an example of how to build a filter form, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
There's a downloadable example to pull apart and see how it works. It does
involve using VBA code to build a string. It will be similar to what you
have done in Excel, though the idea of Null might be new for you. (A field
is null if there's no value stored there.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

NukeEng85 said:
I have a table with about 8 fields displaying information pertaining to 5
different types of equipment (ex: "equipment type"; "serial number";
"location"; "date adjusted"; "time adjusted")

I want to set up a form in which people from my company can search for a
specific piece of equipment based on equipment type, location, and date
using
3 different combo boxes, and having the results displayed in a table in a
subform.

one initial problem I had was when I tried linking the combo box to the
"equipment type" field, but because there are reapeating entries (there
are
only 5 different types, and they all repeat ex: LPRM, APRM, SRM, IRM,
there
are about 20 LPRM, 10 APRM, etc) when I went to view my form and try the
combo box, the available options were LPRM repeated 20 times, etc.

I am very new to access and don't know how to link the combo box selection
to filter the subform data, especially if I'm typing in the values for the
combo box to choose from instead of linking them to a field on my table.

I JUST learned what a query is, if that gives you an idea of my Access
level. I am very competent in Excel, and have done some Macros and Visual
Basic before in Excel

I have Access 2003
 
S

Stuart McCall

Douglas J. Steele said:
Presumably you removed the Stop statement...

Incidentally, using Stop is seldom a good idea, as it doesn't do any
cleanup after itself.
<snip>

Interesting statement, Doug. What do you mean?
 
D

Douglas J. Steele

Stuart McCall said:
<snip>

Interesting statement, Doug. What do you mean?

From the Help file:

"The Stop statement suspends execution, but unlike End, it doesn't close any
files or clear variables"

I know this was the topic of a huge thread in one of the VB newsgroups a few
years ago, but I don't remember any good examples from that discussion.
 
S

Stuart McCall

Douglas J. Steele said:
From the Help file:

"The Stop statement suspends execution, but unlike End, it doesn't close
any files or clear variables"

I know this was the topic of a huge thread in one of the VB newsgroups a
few years ago, but I don't remember any good examples from that
discussion.

Ok, thanks Doug. I don't use Stop myself, just curious.
 

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