Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    255
    You must modify the Sql predicate of the DoctorAndPodiatristQ query, without the need for any parameter declaration, as follows
    Code:
    SELECT ResidentsName, AppointmentTime, DoctorOrPodiatrist FROM DoctorAndPodiatristTB WHERE DoctorOrPodiatrist = [DoctorOrPodiatristParameter]
    and leave the line of code for sending the email unchanged
    Code:
    DoCmd.SendObject acSendQuery, "DoctorAndPodiatristQ", acFormatRTF, "rwshea220540@outlook.com", , , "Test", "Sending an email from VBA"


  2. #17
    Rico is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Perth Australia
    Posts
    29
    I have given up on trying to alter a query's parameter in code, so I will do it the long way with the code below.

    ''My DocAndPodTB contains 6 rows. ID, AppointmentDate, DorP, BNumbAndGender, AppointmentTime,Selected.
    ''My DocAndPodEmailQ contains 4 rows. SurnameSpaceGiven(from RintheVTB), AppointmentTime(Ascending), DorP, AppointmentDate

    DoCmd.SetWarnings False
    DoCmd.OpenQuery "TempDocAndPodEmailDeleteQ", acNormal, acEdit
    DoCmd.SetWarnings True

    Set InRS = mydb.OpenRecordset("Select * from DocAndPodEmailQ where DorP = '" & DocAndPodCurrentDorP & "' and AppointmentDate = '" & DocAndPodCurrentDate & "'")

    Do Until InRS.EOF
    Set OutRS = mydb.OpenRecordset("SELECT * FROM TempDocAndPodEmailTB")
    OutRS.AddNew
    OutRS!SurnameSpaceGiven = InRS!SurnameSpaceGiven
    OutRS!AppointmentDate = InRS!AppointmentDate
    OutRS!AppointmentTime = InRS!AppointmentTime
    OutRS.Update
    OutRS.Close
    Set OutRS = Nothing
    InRS.MoveNext
    Loop
    InRS.Close
    Set InRS = Nothing
    DoCmd.SendObject acSendTable, "TempDocAndPodEmailTB", acFormatRTF, "rwshea220540@outlook.com", , , "Appointment times list from RAAFA.", "Appointment names and times for " & CurrentDateOfEvent

    Thanks for all the assistance I got from the members, when I get the time i will revisit this problem. Rico

  3. #18
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,925
    Wow, setting two tempvars would have been so much simpler.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #19
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Just a few of comments:

    From Post #17
    Quote Originally Posted by Rico View Post
    I have given up on trying to alter a query's parameter in code, so I will do it the long way with the code below.

    ''My DocAndPodTB contains 6 rows. ID, AppointmentDate, DorP, BNumbAndGender, AppointmentTime,Selected.
    ''My DocAndPodEmailQ contains 4 rows. SurnameSpaceGiven(from RintheVTB), AppointmentTime(Ascending), DorP, AppointmentDate
    No, they are FIELDS.


    Quote Originally Posted by Rico View Post
    I have given up on trying to alter a query's parameter in code, so I will do it the long way with the code below.
    You don't need to edit the query parameters. All you need is is to have the query reference two unbound text boxes on a form. (or 2 unbound combo boxes)


    Quote Originally Posted by Rico View Post
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "TempDocAndPodEmailDeleteQ", acNormal, acEdit
    DoCmd.SetWarnings True
    The above 3 lines can be replaced with one line of code.
    mydb.Execute "TempDocAndPodEmailDeleteQ", dbFailOnError
    Also, you didn't close OutRS, didn't set it to Nothing and didn't set mydb to Nothing.




    If you posted your dB, it would be easy to show you how to make the changes. Change sensitive info (names and SSN) - need just a few records .... 5 to 10.

  5. #20
    Rico is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Perth Australia
    Posts
    29
    ssanfu, I will start using the: mydb.Execute "TempDocAndPodEmailDeleteQ", dbFailOnError in future.
    I DID close OutRS, you must have missed it, and I didn't know I had to set mydb to Nothing.

    carlettofed, welshgasman, Don't let anyone kid you that when you retire you have plenty of time on your hands, I will get back to you on your suggestion later.
    Rico


  6. #21
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    @Rico,

    Can't believe that I missed it.

    In re-reading the code, I noticed that you open and close the OutRS record set for every appointment. If there are 5 doctors and 5 podiatrists, each with 8 appointments, you will be opening and closing the record set 40 times.
    I rewrote the code the way I would structure it. Since you did not post the full sub, I had to guess at a couple of things.

    Code:
    Sub Test_Rico()
       Dim mydb As DAO.Database
       Dim InRS As DAO.Recordset
       Dim OutRS As DAO.Recordset
       Dim sSQL As String
       
        'Clear the Temp table
       mydb.Execute "TempDocAndPodEmailDeleteQ", dbFailOnError
    
       sSQL = "SELECT *"
       sSQL = sSQL & " FROM DocAndPodEmailQ"
       sSQL = sSQL & " WHERE DorP = '" & DocAndPodCurrentDorP & "' AND AppointmentDate = '" & DocAndPodCurrentDate & "'"    ' *** see below
       'Debug.Print sSQL
    
       'open record sets
       Set InRS = mydb.OpenRecordset(sSQL)
    
      'check for records
       If InRS.BOF And InRS.EOF Then
        MsgBox "No appointments found for " & DocAndPodCurrentDate
          InRS.Close
          Set InRS = Nothing
          Set mydb = Nothing
          Exit sub
       End If
    
       InRS.MoveLast
       InRS.MoveFirst
    
       Set OutRS = mydb.OpenRecordset("SELECT * FROM TempDocAndPodEmailTB")
    
       'populate temp table
       With OutRS
          Do Until InRS.EOF
             .AddNew
             !SurnameSpaceGiven = InRS!SurnameSpaceGiven
             !AppointmentDate = InRS!AppointmentDate
             !AppointmentTime = InRS!AppointmentTime
             .Update
             InRS.MoveNext
          Loop
       End With
    
       'send e-mail
       DoCmd.SendObject acSendTable, "TempDocAndPodEmailTB", acFormatRTF, "rwshea220540@outlook.com", , , "Appointment times list from RAAFA.", "Appointment names and times for " & CurrentDateOfEvent
       
     'close the record sets
       OutRS.Close
       InRS.Close
    
    'destroy the variables
       Set OutRS = Nothing
       Set InRS = Nothing
       Set mydb = Nothing
    End Sub



    ***
    I am curious as to the data type of "DocAndPodCurrentDate". If it is a DateTime type, it should be delimited with hash marks (#).



    Good luck with your project....

  7. #22
    Rico is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Perth Australia
    Posts
    29
    Thank ssanfu, there is some good stuff there, I will take on board what you have said.
    Rico

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 06-22-2019, 02:24 AM
  2. Running SAS program in a Macro
    By PhatRam32 in forum Macros
    Replies: 2
    Last Post: 03-21-2017, 07:31 AM
  3. Replies: 2
    Last Post: 05-31-2016, 01:52 PM
  4. Replies: 1
    Last Post: 03-25-2014, 08:42 AM
  5. Running Query on only 1 row of table.. Criteria?
    By JMac in forum Database Design
    Replies: 5
    Last Post: 04-16-2012, 11:27 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