Results 1 to 7 of 7
  1. #1
    bidbud68 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    19

    Code Problems With Variables

    Hi I have a code that works and I am trying to adapt it for another report bit for some reason I am getting Variable Undefined, is there anything you can see that could be incorrect ?



    Code:
    Option Compare Database
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Global Const JetDateTimeFmt = "\#dd\/mm\/yy hh\:nn\:ss\#;;;\N\u\l\l"
    
       Function Send_Welcome_Letters()
       
       Dim dbsReservations As DAO.Database
       Dim rstWelcome As DAO.Recordset
       Dim strSQL As String
       Dim strEmailRecipient As String
       
       'On Error GoTo ErrorHandler
       
       Set dbsReservations = CurrentDb
       
       strSQL = "SELECT Reservations.ReservationID, Reservations.UnitDescription, Reservations.[Date IN], Reservations.[Date OUT], Reservations.Tenant, Reservations.TenantEmail AS Email, Reservations.SalesPerson, Reservations.[SalesPerson Email] AS Email1 From Reservations WHERE (((Reservations.[Date IN])=Date()+1));"
       Set rstWelcome = dbsReservations.OpenRecordset(strSQL, dbOpenDynaset)
       
       With rstWelcome
         Do Until .EOF
             DoCmd.OpenReport "Welcome Letter", acViewNormal, , "Reservations.ReservationID=" & rstWelcome![Reservations.ReservationID]
             Sleep (20000)
             Call SendWelcomeLetter(rstWelcome![SalesPerson Email], rstWelcome!EmailAddress)
             .MoveNext
         Loop
       End With
    
       rstWelcome.Close
       dbsReservations.Close
       
       Set rstInvoices = Nothing
       Set dbsReservations = Nothing
    
       Exit Function
    
       'ErrorHandler:
       '  MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
    
       End Function

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    On what line? Do the functions being called exist?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    bidbud68 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    19
    It says Item Not Found In This Collection and it highlights the following line :

    DoCmd.OpenReport "Welcome Letter", acViewNormal, , "Reservations.ReservationID=" & rstWelcome![Reservations.ReservationID]

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Well, you've got this line


    Set rstInvoices = Nothing

    and I don't see where rstInvoices has been declared.

    Linq ;0)>

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Try

    DoCmd.OpenReport "Welcome Letter", acViewNormal, , "ReservationID=" & rstWelcome![ReservationID]

    and be sure the report exists.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    bidbud68 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    19
    Thanks so much, it works and there was also that one incorrect reference which I fixed

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 12-29-2011, 03:12 PM
  2. Reports and variables, problems
    By _Boo in forum Reports
    Replies: 3
    Last Post: 06-23-2011, 01:08 PM
  3. Problems Executing SavedQuery in Code
    By RMittelman in forum Programming
    Replies: 4
    Last Post: 06-18-2011, 02:49 PM
  4. Replies: 8
    Last Post: 09-22-2010, 12:30 PM
  5. Merge Code problems
    By kfergus in forum Access
    Replies: 1
    Last Post: 06-01-2006, 03:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums