Wrox Programmer Forums
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 2nd, 2006, 08:54 AM
Registered User
Join Date: May 2006
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

    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.

Old May 2nd, 2006, 08:56 AM
Registered User
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

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.
Old May 3rd, 2006, 07:03 AM
Friend of Wrox
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

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.



Similar Threads
Thread Thread Starter Forum Replies Last Post
run time polymorphism MunishBhatia C# 2005 5 December 12th, 2007 08:38 AM
Design-Time or Run-Time now ? ALGNET .NET Framework 2.0 1 July 31st, 2006 04:43 AM
run time error ashishroyk Java GUI 0 October 8th, 2004 01:42 AM
how two scripts run at a time ? mateenmohd Javascript 8 April 26th, 2004 03:47 AM

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