skea
Registered User.
- Local time
- Today, 12:19
- Joined
- Dec 21, 2004
- Messages
- 342
Hello There, Can some one help me with this.
I have a button which calls a chart report but i need to validate it in that if there no records in the recordset then it displays my message but the problem is that i have failed to find where to put the validation in this where loop code snippet and which type of SQL statement i refer to. Do i create a new SQL statement?,Refer to SQL_str or WHERE_str.
private Sub LineGBtn_Click()
Dim SQL_str As String, WHERE_str As String
Dim newFlag As Boolean
SQL_str = "SELECT QryIncidents.* FROM QryIncidents "
WHERE_str = ""
newFlag = False
If Trim(Me.ChartDist) = "" And Trim(Me.ChartYear) = "" Then
Else
WHERE_str = WHERE_str & "WHERE ("
If Not Trim(Me.ChartDist) = "" Then
WHERE_str = WHERE_str & "((QryIncidents.District)='" & Trim(Me.ChartDist) & "')"
newFlag = True
End If
If Not Trim(Me.ChartYear) = "" Then
If newFlag = True Then
WHERE_str = WHERE_str & " AND "
End If
WHERE_str = WHERE_str & "( (QryIncidents.Year)='" & Trim(Me.ChartYear) & "')"
newFlag = True
End If
WHERE_str = WHERE_str & ")"
SQL_str = SQL_str & " " & WHERE_str
End If
On Error GoTo Err_T
G
n:
CurrentDb.CreateQueryDef "ChartQry", SQL_str
DoEvents
****Here is My Validation but which SQl statement *******
'Dim rs As DAO.Recordset
'Set rs = CurrentDb.OpenRecordset(SQL_str)
'If rs.RecordCount = 0 Then
'MsgBox "No Records To Display Line Graph"
'Exit Sub
'End If
**********************************************
DoCmd.OpenReport "LineGraph", acViewPreview
DoCmd.Close acForm, "ReporterF"
Me.Visible = False
Exit Sub
Err_T:
If Err.Number = 3012 Then
CurrentDb.Execute "drop table ChartQry"
GoTo G
n
End If
End Sub
I have a button which calls a chart report but i need to validate it in that if there no records in the recordset then it displays my message but the problem is that i have failed to find where to put the validation in this where loop code snippet and which type of SQL statement i refer to. Do i create a new SQL statement?,Refer to SQL_str or WHERE_str.
private Sub LineGBtn_Click()
Dim SQL_str As String, WHERE_str As String
Dim newFlag As Boolean
SQL_str = "SELECT QryIncidents.* FROM QryIncidents "
WHERE_str = ""
newFlag = False
If Trim(Me.ChartDist) = "" And Trim(Me.ChartYear) = "" Then
Else
WHERE_str = WHERE_str & "WHERE ("
If Not Trim(Me.ChartDist) = "" Then
WHERE_str = WHERE_str & "((QryIncidents.District)='" & Trim(Me.ChartDist) & "')"
newFlag = True
End If
If Not Trim(Me.ChartYear) = "" Then
If newFlag = True Then
WHERE_str = WHERE_str & " AND "
End If
WHERE_str = WHERE_str & "( (QryIncidents.Year)='" & Trim(Me.ChartYear) & "')"
newFlag = True
End If
WHERE_str = WHERE_str & ")"
SQL_str = SQL_str & " " & WHERE_str
End If
On Error GoTo Err_T
G

CurrentDb.CreateQueryDef "ChartQry", SQL_str
DoEvents
****Here is My Validation but which SQl statement *******
'Dim rs As DAO.Recordset
'Set rs = CurrentDb.OpenRecordset(SQL_str)
'If rs.RecordCount = 0 Then
'MsgBox "No Records To Display Line Graph"
'Exit Sub
'End If
**********************************************
DoCmd.OpenReport "LineGraph", acViewPreview
DoCmd.Close acForm, "ReporterF"
Me.Visible = False
Exit Sub
Err_T:
If Err.Number = 3012 Then
CurrentDb.Execute "drop table ChartQry"
GoTo G

End If
End Sub