how can i write this in case select syntax? please help
If cboSearchType.Text = "Accredited Month" Then
With grdSearchResults
.Rows = .Rows - .Rows + 1
End With
If rs.State = 1 Then rs.Close
SQL = "SELECT * FROM BusinessInfo WHERE " & " AccreditationDate " & " like '" & cboMonths.Text & "%'"
rs.Open SQL, con
While rs.EOF = False
With grdSearchResults
.Redraw = False
.Rows = .Rows + 1
.Row = .Rows - 1
.Col = 1: .Text = grdSearchResults.Rows - 1
.Col = 2: .Text = rs!BusinessName
.Col = 3: .Text = rs!ApplicantType
.Col = 4: .Text = rs!ApplicantName
.Col = 5: .Text = rs!BusinessAddress
.Col = 6: .Text = rs!AccreditationDate
.Redraw = True
End With
rs.MoveNext
Wend
Else
MsgBox "Accredited Business Entry Does not Exist!", vbCritical, "No Records Found!"
txtSEARCH.Text = ""
txtSEARCH.SetFocus
End If
If cboSearchType.Text = "Accredited Year" Then
With grdSearchResults
.Rows = .Rows - .Rows + 1
End With
If rs.State = 1 Then rs.Close
SQL = "SELECT * FROM BusinessInfo WHERE " & " AccreditationDate " & " like '" & txtSEARCH.Text & "%'"
rs.Open SQL, con
While rs.EOF = False
With grdSearchResults
.Redraw = False
.Rows = .Rows + 1
.Row = .Rows - 1
.Col = 1: .Text = grdSearchResults.Rows - 1
.Col = 2: .Text = rs!BusinessName
.Col = 3: .Text = rs!ApplicantType
.Col = 4: .Text = rs!ApplicantName
.Col = 5: .Text = rs!BusinessAddress
.Col = 6: .Text = rs!AccreditationDate
.Redraw = True
End With
rs.MoveNext
Wend
Else
MsgBox "Accredited Business Entry Does not Exist!", vbCritical, "No Records Found!"
txtSEARCH.Text = ""
txtSEARCH.SetFocus
End If
If cboSearchType.Text = "Applicant Name" Then
With grdSearchResults
.Rows = .Rows - .Rows + 1
End With
If rs.State = 1 Then rs.Close
SQL = "SELECT * FROM BusinessInfo WHERE " & " ApplicantName " & " like '" & txtSEARCH.Text & "%'"
rs.Open SQL, con
While rs.EOF = False
With grdSearchResults
.Redraw = False
.Rows = .Rows + 1
.Row = .Rows - 1
.Col = 1: .Text = grdSearchResults.Rows - 1
.Col = 2: .Text = rs!BusinessName
.Col = 3: .Text = rs!ApplicantType
.Col = 4: .Text = rs!ApplicantName
.Col = 5: .Text = rs!BusinessAddress
.Col = 6: .Text = rs!AccreditationDate
.Redraw = True
End With
rs.MoveNext
Wend
Else
MsgBox "Accredited Business Entry Does not Exist!", vbCritical, "No Records Found!"
txtSEARCH.Text = ""
txtSEARCH.SetFocus
End If
If cboSearchType.Text = "Business Name" Then
With grdSearchResults
.Rows = .Rows - .Rows + 1
End With
If rs.State = 1 Then rs.Close
SQL = "SELECT * FROM BusinessInfo WHERE " & " BusinessName " & " like '" & txtSEARCH.Text & "%'"
rs.Open SQL, con
While rs.EOF = False
With grdSearchResults
.Redraw = False
.Rows = .Rows + 1
.Row = .Rows - 1
.Col = 1: .Text = grdSearchResults.Rows - 1
.Col = 2: .Text = rs!BusinessName
.Col = 3: .Text = rs!ApplicantType
.Col = 4: .Text = rs!ApplicantName
.Col = 5: .Text = rs!BusinessAddress
.Col = 6: .Text = rs!AccreditationDate
.Redraw = True
End With
rs.MoveNext
Wend
Else
MsgBox "Accredited Business Entry Does not Exist!", vbCritical, "No Records Found!"
txtSEARCH.Text = ""
txtSEARCH.SetFocus
End If
End Sub
it is too many lines and i want to make it short because this lines is being repeated 4 times already
MsgBox "Accredited Business Entry Does not Exist!", vbCritical, "No Records Found!"
txtSEARCH.Text = ""
txtSEARCH.SetFocus
also this one, maybe i could use case select syntax to just type the sql statement as you see it is so dirty coding i am just a beginer so sorry for this..i hope you understand
While rs.EOF = False
With grdSearchResults
.Redraw = False
.Rows = .Rows + 1
.Row = .Rows - 1
.Col = 1: .Text = grdSearchResults.Rows - 1
.Col = 2: .Text = rs!BusinessName
.Col = 3: .Text = rs!ApplicantType
.Col = 4: .Text = rs!ApplicantName
.Col = 5: .Text = rs!BusinessAddress
.Col = 6: .Text = rs!AccreditationDate
.Redraw = True
End With
rs.MoveNext
Wend