i dont know what im doing wrong.. i have a form that will print out a report after choosing options in the combo boxes... then my filtering code is like this:
Option Compare Database ' Use database order for string comparisons '
Option Explicit
Global RapString
Sub AddToWhere(FieldValue As Variant, FieldName As String, MyCriteria As String, Argcount As Integer, Argument As Variant)
If IsNull(FieldValue) Then Exit Sub
If FieldValue = "" Then Exit Sub
If (Left(FieldValue, 1) = "'"
Or (Left(FieldValue, 1) = "#"
Then
If Len(FieldValue) < 3 Then Exit Sub
End If
If Argcount > 0 Then MyCriteria = MyCriteria & " and "
Select Case Argument
Case "Like"
MyCriteria = (MyCriteria & FieldName & " Like " & Chr(39) & FieldValue & Chr(42) & Chr(42) & Chr(39))
Case Else
MyCriteria = (MyCriteria & FieldName & " " & Argument & " " & FieldValue)
End Select
Argcount = Argcount + 1
End Sub
Function HumanRecordsource(H_Severity, H_Freq, H_FreqTo, H_Risk)
Dim MySql As String, MyCriteria As String, MyRecordsource As String
Dim Argcount As Integer
Dim Tmp As Variant
Argcount = 0
MySql = "SELECT * From Human WHERE "
MyCriteria = ""
AddToWhere "'" & H_Severity & "'", "[Human_Severity_Class]", MyCriteria, Argcount, "="
If Not IsNull(H_Freq) Then AddToWhere "'" & H_Freq & "'", "[Human_Frequency]", MyCriteria, Argcount, ">="
If Not IsNull(H_FreqTo) Then AddToWhere "'" & H_FreqTo & "'", "[Human_Frequency]", MyCriteria, Argcount, "<="
AddToWhere "'" & H_Risk & "'", "[Risk_Class_Human]", MyCriteria, Argcount, "="
If MyCriteria = "" Then MyCriteria = "True"
HumanRecordsource = MySql & MyCriteria
RapString = MySql & MyCriteria
End Function
and this works when i want to print out a normal report... but now i have a report that i made through crosstab query... and yer supposed to print this out too through the combo boxes... but i cant get this to work.. this is the code from class object for the report
Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = RapString
Dim I As Integer
For I = 0 To 7
ReportLabel(I) = ""
Next I
Call CreateReportQuery
End Sub
Sub CreateReportQuery()
On Error GoTo Err_CreateQuery
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim fld As DAO.Field
Dim indexx As Integer
Dim FieldList As String
Dim strSQL As String
Dim I As Integer
Set db = CurrentDb
Set qdf = db.QueryDefs("ProCrosstab"
indexx = 0
For Each fld In qdf.Fields
If fld.Type >= 1 And fld.Type <= 8 Or fld.Type = 10 Then
FieldList = FieldList & "[" & fld.Name & "] as Field" & indexx & ", "
ReportLabel(indexx) = fld.Name
End If
' MsgBox Label(indexx)
indexx = indexx + 1
Next fld
For I = indexx To 7
FieldList = FieldList & "null as Field" & I & ","
Next I
FieldList = Left(FieldList, Len(FieldList) - 2)
strSQL = "Select " & FieldList & " From ProCrosstab"
db.QueryDefs.Delete "CrossTabReportP"
Set qdf = db.CreateQueryDef("CrossTabReportP", strSQL)
Exit_CreateQuery:
Exit Sub
Err_CreateQuery:
If Err.Number = 3265 Then '*** if the error is the query is missing
Resume Next '*** then skip the delete line and resume on the next line
Else
MsgBox Err.Description '*** write out the error and exit the sub
Resume Exit_CreateQuery
End If
End Sub
Function FillLabel(LabelNumber As Integer) As String
FillLabel = Nz(ReportLabel(LabelNumber), ""
End Function
am i supposed to make a whole new query?
Option Compare Database ' Use database order for string comparisons '
Option Explicit
Global RapString
Sub AddToWhere(FieldValue As Variant, FieldName As String, MyCriteria As String, Argcount As Integer, Argument As Variant)
If IsNull(FieldValue) Then Exit Sub
If FieldValue = "" Then Exit Sub
If (Left(FieldValue, 1) = "'"
If Len(FieldValue) < 3 Then Exit Sub
End If
If Argcount > 0 Then MyCriteria = MyCriteria & " and "
Select Case Argument
Case "Like"
MyCriteria = (MyCriteria & FieldName & " Like " & Chr(39) & FieldValue & Chr(42) & Chr(42) & Chr(39))
Case Else
MyCriteria = (MyCriteria & FieldName & " " & Argument & " " & FieldValue)
End Select
Argcount = Argcount + 1
End Sub
Function HumanRecordsource(H_Severity, H_Freq, H_FreqTo, H_Risk)
Dim MySql As String, MyCriteria As String, MyRecordsource As String
Dim Argcount As Integer
Dim Tmp As Variant
Argcount = 0
MySql = "SELECT * From Human WHERE "
MyCriteria = ""
AddToWhere "'" & H_Severity & "'", "[Human_Severity_Class]", MyCriteria, Argcount, "="
If Not IsNull(H_Freq) Then AddToWhere "'" & H_Freq & "'", "[Human_Frequency]", MyCriteria, Argcount, ">="
If Not IsNull(H_FreqTo) Then AddToWhere "'" & H_FreqTo & "'", "[Human_Frequency]", MyCriteria, Argcount, "<="
AddToWhere "'" & H_Risk & "'", "[Risk_Class_Human]", MyCriteria, Argcount, "="
If MyCriteria = "" Then MyCriteria = "True"
HumanRecordsource = MySql & MyCriteria
RapString = MySql & MyCriteria
End Function
and this works when i want to print out a normal report... but now i have a report that i made through crosstab query... and yer supposed to print this out too through the combo boxes... but i cant get this to work.. this is the code from class object for the report
Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = RapString
Dim I As Integer
For I = 0 To 7
ReportLabel(I) = ""
Next I
Call CreateReportQuery
End Sub
Sub CreateReportQuery()
On Error GoTo Err_CreateQuery
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim fld As DAO.Field
Dim indexx As Integer
Dim FieldList As String
Dim strSQL As String
Dim I As Integer
Set db = CurrentDb
Set qdf = db.QueryDefs("ProCrosstab"
indexx = 0
For Each fld In qdf.Fields
If fld.Type >= 1 And fld.Type <= 8 Or fld.Type = 10 Then
FieldList = FieldList & "[" & fld.Name & "] as Field" & indexx & ", "
ReportLabel(indexx) = fld.Name
End If
' MsgBox Label(indexx)
indexx = indexx + 1
Next fld
For I = indexx To 7
FieldList = FieldList & "null as Field" & I & ","
Next I
FieldList = Left(FieldList, Len(FieldList) - 2)
strSQL = "Select " & FieldList & " From ProCrosstab"
db.QueryDefs.Delete "CrossTabReportP"
Set qdf = db.CreateQueryDef("CrossTabReportP", strSQL)
Exit_CreateQuery:
Exit Sub
Err_CreateQuery:
If Err.Number = 3265 Then '*** if the error is the query is missing
Resume Next '*** then skip the delete line and resume on the next line
Else
MsgBox Err.Description '*** write out the error and exit the sub
Resume Exit_CreateQuery
End If
End Sub
Function FillLabel(LabelNumber As Integer) As String
FillLabel = Nz(ReportLabel(LabelNumber), ""
End Function
am i supposed to make a whole new query?