Multiple Combo Boxes

P

Priss

By selection of combo boxes to provide data in the
subform. If I don't select any combo, then ALL records
show in the subform. (i.e. select combo1 - shows records
equal to combo1, then I select combo2 as - shows records
equal to combo1 and combo. Same with combo30. Not sure
if I am making any sense. My combo1 works when selected,
but combo2 comes up by default for whatever APPID is
first. I made the change with the master/child link -
combo1 & combo2 works, but combo3 will not. So i know it
has something do with what I am doing. I would like not
have to code at all to make this work since I am not
experience with it. I am also trying to understand the
other code changes that you specified - working with it.
-----Original Message-----
I know this can be very frustrating at times and I do
apologize as well for thinking the worse because I had not
gotten a response from previous post of the same issue.
Here is the code that I have provided w/revisions:

Comments inline.
Private Function FilterData() As DAO.Recordset
On Error GoTo err_routine

Dim ErrorValue As String
Dim APPSYSID As String
Dim SalesID As String
Dim FilterValue As String
Dim SQL As String
Dim rs As DAO.Recordset
Dim myDB As DAO.Database

' get the value of the Error from the combo box
Me.cboError.SetFocus
ErrorValue = Me.cboError.Text

You can also determine the contents of a control by examining its
Value property. It's not necessary to setfocus to it in that case. If
you Dim ErrorValue as a Variant instead of a String it will accept
NULL - see below.
' get the value of the AppSysID from the combo box
Me.cboAppID.SetFocus
APPSYSID = Me.cboAppID.Text

' get the value of the SalesID from the combo box
'Me.cboSalesID.SetFocus
'SalesID = Me.cboSalesID.Text

Commented out intentionally?
' get an instance of the database
Set myDB = CurrentDb

' set up the filter
SQL = "SELECT * FROM [tblExclude] "

If Len(Trim$(ErrorValue & "")) > 0 Then
'we have an error value

If Len(Trim$(APPSYSID & "")) > 0 Then
'we have a app sys id
SQL = SQL & "where [Error]=" & ErrorValue & "
and [APP SYS ID]=" & APPSYSID & ""

If Error is a Text datatype field you'll need the syntactically
required quote marks:

"where [Error] = '" & [ErrorValue] & "' and...

If it's numeric your code should work as written.
Else
'we do not have an app sys id
SQL = SQL & "where [Error]=" & ErrorValue

'we do not have a error value

End If

Else

If Len(Trim$(APPSYSID & "")) > 0 Then
'we have a app sys id
SQL = SQL & "where [APP SYS ID]=" & APPSYSID

Same concern about Text fields.
Else
'we do not have an app sys id
'do not change the SQL
End If
End If

Set rs = myDB.OpenRecordset(SQL)
Set FilterData = rs
Exit Function
err_routine:
MsgBox "Error " & Err.Number & ": " & Err.Description,
vbOKOnly + vbInformation, "Error"
Set FilterData = Nothing
Exit Function

End Function

Private Sub cboAPPID_AfterUpdate()
Set Me.Recordset = FilterData

End Sub

Private Sub cboError_AfterUpdate()
Set Me.Recordset = FilterData

End Sub

... <code snipped, irrelevant to this problem>

Private Sub Description_AfterUpdate()
Me!tblExclude_Error!Description = Me!Description

End Sub

Private Sub Form_Load()
'clear screen
cboError = ""
cboAppID = ""
'cboSalesID=""

Set these to NULL rather than to a zero length string.
cboError.SetFocus

End Sub

So... a couple of questions:

- What's happening when you select a value from the combo box?
- What do you WANT to happen?

If you just want to display records from tblExclude which match the
combo box criteria, there are two perhaps easier ways to do so. First,
build your SQL and set the RecordSource property of the Query to that
string (since the Recordsource is a string property, not a Recordset
property); second, use *no code at all*, and instead put a Subform on
your form based on tblExclude. Set its Master Link Field property to

[cboError];[cboAppID];[cboSalesID]

and its Child Link Field to

[ErrorID];[AppID];[SalesID]

It should filter the data on the basis of these fields. You'll
probably need to Requery the subform in the AfterUpdate event of each
combo box.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
.
..
 
P

Priss

John -
I think we lost connection with one another. Didn't want
to keep re-posting for a response.

-----Original Message-----
By selection of combo boxes to provide data in the
subform. If I don't select any combo, then ALL records
show in the subform. (i.e. select combo1 - shows records
equal to combo1, then I select combo2 as - shows records
equal to combo1 and combo. Same with combo30. Not sure
if I am making any sense. My combo1 works when selected,
but combo2 comes up by default for whatever APPID is
first. I made the change with the master/child link -
combo1 & combo2 works, but combo3 will not. So i know it
has something do with what I am doing. I would like not
have to code at all to make this work since I am not
experience with it. I am also trying to understand the
other code changes that you specified - working with it.
-----Original Message-----
I know this can be very frustrating at times and I do
apologize as well for thinking the worse because I had not
gotten a response from previous post of the same issue.
Here is the code that I have provided w/revisions:

Comments inline.
Private Function FilterData() As DAO.Recordset
On Error GoTo err_routine

Dim ErrorValue As String
Dim APPSYSID As String
Dim SalesID As String
Dim FilterValue As String
Dim SQL As String
Dim rs As DAO.Recordset
Dim myDB As DAO.Database

' get the value of the Error from the combo box
Me.cboError.SetFocus
ErrorValue = Me.cboError.Text

You can also determine the contents of a control by examining its
Value property. It's not necessary to setfocus to it in that case. If
you Dim ErrorValue as a Variant instead of a String it will accept
NULL - see below.
' get the value of the AppSysID from the combo box
Me.cboAppID.SetFocus
APPSYSID = Me.cboAppID.Text

' get the value of the SalesID from the combo box
'Me.cboSalesID.SetFocus
'SalesID = Me.cboSalesID.Text

Commented out intentionally?
' get an instance of the database
Set myDB = CurrentDb

' set up the filter
SQL = "SELECT * FROM [tblExclude] "

If Len(Trim$(ErrorValue & "")) > 0 Then
'we have an error value

If Len(Trim$(APPSYSID & "")) > 0 Then
'we have a app sys id
SQL = SQL & "where [Error]=" & ErrorValue & "
and [APP SYS ID]=" & APPSYSID & ""

If Error is a Text datatype field you'll need the syntactically
required quote marks:

"where [Error] = '" & [ErrorValue] & "' and...

If it's numeric your code should work as written.
Else
'we do not have an app sys id
SQL = SQL & "where [Error]=" & ErrorValue

'we do not have a error value

End If

Else

If Len(Trim$(APPSYSID & "")) > 0 Then
'we have a app sys id
SQL = SQL & "where [APP SYS ID]=" & APPSYSID

Same concern about Text fields.
Else
'we do not have an app sys id
'do not change the SQL
End If
End If

Set rs = myDB.OpenRecordset(SQL)
Set FilterData = rs
Exit Function
err_routine:
MsgBox "Error " & Err.Number & ": " & Err.Description,
vbOKOnly + vbInformation, "Error"
Set FilterData = Nothing
Exit Function

End Function

Private Sub cboAPPID_AfterUpdate()
Set Me.Recordset = FilterData

End Sub

Private Sub cboError_AfterUpdate()
Set Me.Recordset = FilterData

End Sub

... <code snipped, irrelevant to this problem>

Private Sub Description_AfterUpdate()
Me!tblExclude_Error!Description = Me!Description

End Sub

Private Sub Form_Load()
'clear screen
cboError = ""
cboAppID = ""
'cboSalesID=""

Set these to NULL rather than to a zero length string.
cboError.SetFocus

End Sub

So... a couple of questions:

- What's happening when you select a value from the
combo
box?
- What do you WANT to happen?

If you just want to display records from tblExclude
which
match the
combo box criteria, there are two perhaps easier ways to do so. First,
build your SQL and set the RecordSource property of the Query to that
string (since the Recordsource is a string property, not a Recordset
property); second, use *no code at all*, and instead put a Subform on
your form based on tblExclude. Set its Master Link Field property to

[cboError];[cboAppID];[cboSalesID]

and its Child Link Field to

[ErrorID];[AppID];[SalesID]

It should filter the data on the basis of these fields. You'll
probably need to Requery the subform in the AfterUpdate event of each
combo box.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
.
..


.
 
J

John Vinson

John -
I think we lost connection with one another. Didn't want
to keep re-posting for a response.

sorry Priss - I thought from your message that you had resolved the
issue.

I *THINK* this can be done with one line of code for each combo.

To do so, base the Subform on a Query referencing the three combo
boxes as criteria:

WHERE ([ErrorID] = [Forms]![yourform]![cboErrorID] OR
[Forms]![yourform]![cboErrorID] IS NULL)
AND ([AppID] = [Forms]![yourform]![cboAppID] OR
[Forms]![yourform]![cboAppID] IS NULL)
AND ([SalesID] = [Forms]![yourform]![cboSalesID] OR
[Forms]![yourform]![cboSalesID] IS NULL)

In the AfterUpdate event of each combo, just requery the subform.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
P

Priss

Since I know very little about this - still confused and
nothing is working. Can you set a combo example up for me
please?
-----Original Message-----
John -
I think we lost connection with one another. Didn't want
to keep re-posting for a response.

sorry Priss - I thought from your message that you had resolved the
issue.

I *THINK* this can be done with one line of code for each combo.

To do so, base the Subform on a Query referencing the three combo
boxes as criteria:

WHERE ([ErrorID] = [Forms]![yourform]![cboErrorID] OR
[Forms]![yourform]![cboErrorID] IS NULL)
AND ([AppID] = [Forms]![yourform]![cboAppID] OR
[Forms]![yourform]![cboAppID] IS NULL)
AND ([SalesID] = [Forms]![yourform]![cboSalesID] OR
[Forms]![yourform]![cboSalesID] IS NULL)

In the AfterUpdate event of each combo, just requery the subform.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
.
 
J

John Vinson

Since I know very little about this - still confused and
nothing is working. Can you set a combo example up for me
please?

Ummm... I thought I did.

Could you post the SQL view of the query you're trying to use, and the
names of the form controls?

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 

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