N
NukeEng85
so I have two combo boxes in a form and I need to be able to look up data
with either one or both, meaning i need one to have an "all" option (or just
be null). I tried putting this in the rowsource:
SELECT DISTINCT [SNM Data].[SNM Type] FROM [SNM Data] UNION Select Null as
AllChoice, "(All)" as Bogus From [SNM Data]
ORDER BY [SNM Data].[SNM Type];
and it gave me an error message that says: "The number of columns in the two
selected tables or queries of a union query do not match."
I also tried changing the criteria for the field that is being filtered in
the query to this:
Forms!NameOfForm!NameOfCombo Or (Forms!NameOfForm!NameOfCombo = "any")
Another problem I'm having is that I have a command button that is supposed
to use the values selected in the combo box to filter data from the table
into a subform (basically filtering and locating records) I am using the
below code, and for some reason if I exit the form and pull it back up the
button stops working unless I first right click the form, select "Filter by
form" and then "apply filter/sort" I want other people at my work to just be
able to pull this up and find what they need via the combo boxes, so I really
need it to work automatically.
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
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
with either one or both, meaning i need one to have an "all" option (or just
be null). I tried putting this in the rowsource:
SELECT DISTINCT [SNM Data].[SNM Type] FROM [SNM Data] UNION Select Null as
AllChoice, "(All)" as Bogus From [SNM Data]
ORDER BY [SNM Data].[SNM Type];
and it gave me an error message that says: "The number of columns in the two
selected tables or queries of a union query do not match."
I also tried changing the criteria for the field that is being filtered in
the query to this:
Forms!NameOfForm!NameOfCombo Or (Forms!NameOfForm!NameOfCombo = "any")
Another problem I'm having is that I have a command button that is supposed
to use the values selected in the combo box to filter data from the table
into a subform (basically filtering and locating records) I am using the
below code, and for some reason if I exit the form and pull it back up the
button stops working unless I first right click the form, select "Filter by
form" and then "apply filter/sort" I want other people at my work to just be
able to pull this up and find what they need via the combo boxes, so I really
need it to work automatically.
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
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub