p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access VBA (http://p2p.wrox.com/forumdisplay.php?f=80)
-   -   Run time Help (http://p2p.wrox.com/showthread.php?t=41988)

Dazzer96 May 2nd, 2006 08:54 AM

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.



Dazzer96 May 2nd, 2006 08:56 AM

Sorry forgot to add, if i enter the dates correctly they work fine but if i enter one number too much thats when the runn error occurs. Also any useful links where i can learn more on how to handle error trapping would be of great use.

mmcdonal May 3rd, 2006 07:03 AM

If its only a data entry issue, use data validation at the table level to prevent improperly entered dates. Also, use a date picker to prevent improperly entered dates.

See: http://msdn.microsoft.com/office/understanding/access/ for Access help. Also www.advisor.com for Access Advisor.

HTH

mmcdonal


All times are GMT -4. The time now is 07:30 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.