Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 2nd, 2006, 08:54 AM
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

    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.

Reply With Quote
  #2 (permalink)  
Old May 2nd, 2006, 08:56 AM
Registered User
Join Date: May 2006
Location: , , .
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.
Reply With Quote
  #3 (permalink)  
Old May 3rd, 2006, 07:03 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Mar 2004
Location: Washington, DC, USA.
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.


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 03:16 AM.

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