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

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

    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

    intCounter = rec.RecordCount

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

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


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.



All times are GMT -4. The time now is 08:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.