Thread: Run time Help
View Single Post
  #1 (permalink)  
Old May 2nd, 2006, 08:54 AM
Dazzer96 Dazzer96 is offline
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Run time Help

I am not very good with coding and am a real new at VB, i need help with error trapping when using dates with forms. i get a run time error 13. Following code:


Public Sub FormDates()

    Dim db As Database
    Dim rec As Recordset
    Dim strSql As String
    Dim strMatches As String
    Dim intCounter As Integer
    Dim Textbox1, Textbox2 As Date

If IsNull(Form_DATES.Text1) Or IsNull(Form_DATES.Text3) Then

    MsgBox "Please enter a Date"

    Exit Sub
    End If


    Form_DATES.Text1.SetFocus
    Textbox1 = Format$(Form_DATES.Text1, "DD/MM/YY")


    Form_DATES.Text3.SetFocus
    Textbox2 = Format$(Form_DATES.Text3.Text, "DD/MM/YY")

    If Not IsNull(Form_DATES.Text1) And (Textbox1 >= Textbox2) Then
    MsgBox "You need to enter the Latest Date in the First Textbox"

    Exit Sub

    End If

    Let strSql = "SELECT * FROM tblMembership "

    Let strSql = strSql & "WHERE tblMembership.[DateOfBirth] >= #" & Textbox1 & "#"

    Let strSql = strSql & " AND tblMembership.[DateOfBirth] <= #" & Textbox2 & "#"

 MsgBox (strSql)


    Set db = CurrentDb()
    Set rec = db.OpenRecordset(strSql, dbOpenSnapshot)

    Do Until rec.EOF
        strMatches = strMatches & Chr$(10) & rec!Surname
        rec.MoveNext

    Loop
    intCounter = rec.RecordCount

    Select Case intCounter
    Case 0
        Form_DATES.Text5.SetFocus
        Form_DATES.Text5.Text = "No members match this Category Rating"

    Case Else
        Form_DATES.Text5.SetFocus
        Form_DATES.Text5.Text = Chr$(10) & strMatches
    End Select

        rec.Close

End Sub


thats the entire code so its not much.

i know i can stop the errors by formatting the textboxes in the forms, but information on how to stop the errors while changing the code will be more helpful.

Thanks in advance for any help given.


Reply With Quote