Results 1 to 9 of 9

Thread: Help with this?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    344

    Help with this?

    I have the following code that check if the birthday is less than 15 days it will prompt a reminder window when the program starts. But the problem is that when I delete all the records in the database, it will show and error msg "Run-time error '3021' : No current record." Whats is a problem here and how can I show this?

    VB Code:
    1. Private Sub Form_Load()
    2.   Width = 8580
    3.   Height = 3705
    4.   Dim TempDate As Date
    5.   Dim Count As Integer
    6.   Count = 0
    7.   Set Table = frmMain.DB.OpenRecordset("SELECT * FROM CONTACTS ORDER BY LNAME DESC")
    8.     With Table
    9.         .MoveFirst
    10.         Do While Not .EOF
    11.             TempDate = !BDayM & "/" & !BDayD & "/" & Year(Date)
    12.             If Abs(GetDays(TempDate)) < 15 Then
    13.                 List1.AddItem "Birthday - " & !Fname & " " & !LName & "  (" & GetDays(TempDate) & " days)"
    14.                 Recs(Count) = !LName & ", " & !Fname
    15.                 Pics(Count) = !pic
    16.                 Count = Count + 1
    17.             End If
    18.             .MoveNext
    19.         Loop
    20.     End With
    21. End Sub

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Help with this?

    Take out the MoveFirst statement, it is not needed. When a recordset is Open it is already on the first record.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    344

    Re: Help with this?

    Quote Originally Posted by brucevde
    Take out the MoveFirst statement, it is not needed. When a recordset is Open it is already on the first record.
    So it will be like this?

    VB Code:
    1. Private Sub Form_Load()
    2.   Width = 8580
    3.   Height = 3705
    4.   Dim TempDate As Date
    5.   Dim Count As Integer
    6.   Count = 0
    7.   Set Table = frmMain.DB.OpenRecordset("SELECT * FROM CONTACTS ORDER BY LNAME DESC")
    8.     With Table
    9.             Do While Not .EOF
    10.             TempDate = !BDayM & "/" & !BDayD & "/" & Year(Date)
    11.             If Abs(GetDays(TempDate)) < 15 Then
    12.                 List1.AddItem "Birthday - " & !Fname & " " & !LName & "  (" & GetDays(TempDate) & " days)"
    13.                 Recs(Count) = !LName & ", " & !Fname
    14.                 Pics(Count) = !pic
    15.                 Count = Count + 1
    16.             End If
    17.             .MoveNext
    18.         Loop
    19.     End With
    20. End Sub


  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    11,044

    Re: Help with this?

    Have you tried if removing the MoveFirst fixes the problem?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    344

    Re: Help with this?

    Quote Originally Posted by dee-u
    Have you tried if removing the MoveFirst fixes the problem?
    Yah, it solves the problem but just found another new problem. When I add a contact and I never key in the birth date. Then when I restart the application, it shows me an error "Run-time error '13' : Type mismatch".

    VB Code:
    1. Private Sub Form_Load()
    2.   Width = 8580
    3.   Height = 3705
    4.   Dim TempDate As Date
    5.   Dim Count As Integer
    6.   Count = 0
    7.   Set Table = frmMain.DB.OpenRecordset("SELECT * FROM CONTACTS ORDER BY LNAME DESC")
    8.     With Table
    9.         Do While Not .EOF
    10.             TempDate = !BDayM & "/" & !BDayD & "/" & Year(Date)  <-- error
    11.             If Abs(GetDays(TempDate)) < 15 Then
    12.                 List1.AddItem "Birthday - " & !Fname & " " & !LName & "  (" & GetDays(TempDate) & " days)"
    13.                 Recs(Count) = !LName & ", " & !Fname
    14.                 Pics(Count) = !pic
    15.                 Count = Count + 1
    16.             End If
    17.             .MoveNext
    18.         Loop
    19.     End With
    20. End Sub

    Please advice...

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    11,044

    Re: Help with this?

    You would have to check for the nullity of the field like...

    VB Code:
    1. Private Sub Form_Load()
    2.   Width = 8580
    3.   Height = 3705
    4.   Dim TempDate As Date
    5.   Dim Count As Integer
    6.   Count = 0
    7.   Set Table = frmMain.DB.OpenRecordset("SELECT * FROM CONTACTS ORDER BY LNAME DESC")
    8.     With Table
    9.         Do While Not .EOF
    10.             If IsNull(!BDayM) Then
    11.                 TempDate = vbNullString
    12.             Else
    13.                 TempDate = !BDayM & "/" & !BDayD & "/" & year(Date) < --Error
    14.             End If
    15.             If Abs(GetDays(TempDate)) < 15 Then
    16.                 List1.AddItem "Birthday - " & !Fname & " " & !LName & "  (" & GetDays(TempDate) & " days)"
    17.                 Recs(Count) = !LName & ", " & !Fname
    18.                 Pics(Count) = !pic
    19.                 Count = Count + 1
    20.             End If
    21.             .MoveNext
    22.         Loop
    23.     End With
    24. End Sub

    Though you should mofidy if further for your GetDays procedure...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    344

    Re: Help with this?

    Im still getting the same error. I have the following code for my GetDays procedure.

    VB Code:
    1. Public Function GetDays(BDate As Date) As Integer
    2.     If DateDiff("d", Date, BDate) < 1 Then
    3.         BDate = Month(BDate) & "/" & Day(BDate) & "/" & Year(BDate) + 1
    4.     End If
    5.     GetDays = DateDiff("d", Date, BDate)
    6. End Function

    Please advice...

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Help with this?

    Quote Originally Posted by weisi
    Im still getting the same error. I have the following code for my GetDays procedure.

    VB Code:
    1. Public Function GetDays(BDate As Date) As Integer
    2.     If DateDiff("d", Date, BDate) < 1 Then
    3.         [b]If IsDate(Month(BDate) & "/" & Day(BDate) & "/" & Year(BDate) + 1) Then[/b]
    4.           BDate = Month(BDate) & "/" & Day(BDate) & "/" & Year(BDate) + 1
    5.        [b]Else
    6.           BDate = "01/01/1801"
    7.        End If[/b]
    8.     End If
    9.     [b]If BDate = "01/01/1801" then
    10.       GetDays = -1
    11.     Else[/b]
    12.       GetDays = DateDiff("d", Date, BDate)
    13.     [b]End If[/b]
    14. End Function
    Check whether the date is a date before using it as one. If it's not you'll need some indication, like GetDays being -1.

    Do the same kind of checking in your other routine.

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    11,044

    Re: Help with this?

    Didn't you read my last sentence in my previous post? Anyway here it is, modify it to suit your needs....

    VB Code:
    1. Private Sub Form_Load()
    2.   Width = 8580
    3.   Height = 3705
    4.   Dim TempDate As Date
    5.   Dim Count As Integer
    6.   Count = 0
    7.   Set Table = frmMain.DB.OpenRecordset("SELECT * FROM CONTACTS ORDER BY LNAME DESC")
    8.     With Table
    9.         Do While Not .EOF
    10.             If IsNull(!BDayM) Then
    11.                 TempDate = vbNullString
    12.             Else
    13.                 TempDate = !BDayM & "/" & !BDayD & "/" & year(Date) < --Error
    14.             End If
    15.             If Abs(GetDays(TempDate)) < 15 Then
    16.                 If TempDate = vbNullString Then
    17.                     MsgBox "No birthday!"
    18.                 Else
    19.                     List1.AddItem "Birthday - " & !Fname & " " & !LName & "  (" & GetDays(TempDate) & " days)"
    20.                 End If
    21.                 Recs(Count) = !LName & ", " & !Fname
    22.                 Pics(Count) = !pic
    23.                 Count = Count + 1
    24.             End If
    25.             .MoveNext
    26.         Loop
    27.     End With
    28. End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width