473,473 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

access 2013 - runtime 3061

22 New Member
I have been trying to build an OnClick in Access VBA to send separate outlook emails with corresponding attachments from an Access query. I have found a bit of old code that I am trying to adapt.
This is for monthly invoice statements.

I have a parameter in the query to pull the exact attachments I need by date.

My query records start with a unique(Autonumber) id, and includes the e-mail address and the path to the attachment, The attachment is on the same drive/network.

This is an example of a query record
STID CustID ACCT APCEmail STMTAP STDATE STMTPATH
30 740 999999 hmb@123.com TRUE 1/5/2019 C:\Users\Summaries\EMAIL\999999.xlsx

My first problem is on Set rsEmail, runtime 3061 with two few parameters. Is this VBA correct to open a parameter query?
Expand|Select|Wrap|Line Numbers
  1. Dim MyDb As DAO.Database
  2. Dim rsEmail As DAO.Recordset
  3. Dim sToName As String
  4. Dim sSubject As String
  5. Dim sMessageBody As String
  6.  
  7. Set MyDb = CurrentDb()
  8. Set rsEmail = MyDb.OpenRecordset("qrysendEMstmt", dbOpenSnapshot)
  9.  
  10. With rsEmail
  11.         .MoveFirst
  12.         Do Until rsEmail.EOF
  13.             If IsNull(.Fields(3)) = False Then
  14.                 sToName = .Fields(3) 
  15.                 sSubject = "SG Acct Summary: " & .Fields(2) 
  16.                 sMessageBody = ""Please find attached account summary for your reconciliation." & vbNewLine & "Kindly feedback payment status." & vbNewLine & "Thank you!"
  17.  
  18.                 DoCmd.SendObject acSendObject, , , _
  19.                     sToName, , , sSubject, sMessageBody, False, False
  20.             End If
  21.             .MoveNext
  22.         Loop
  23. End With
  24.  
  25. Set MyDb = Nothing
  26. Set rsEmail = Nothing
  27.  
Thank you for any input so I can continue to test this.....
Jan 5 '19 #1
3 1224
twinnyfo
3,653 Recognized Expert Moderator Specialist
My guess is that your error is in qrysendEMstmt.

Please post your SQL for that Query and we can take a look.

This error can happen sometimes when you are using references to open forms.

Hope this hepps!
Jan 7 '19 #2
MC42015
22 New Member
thank you for your guidance!
This qry has two parameters that I can work around (if that is the problem!)
One is the date - to pull the records I want
The other is for testing - to pull fake account that e-mails to me feature -

Expand|Select|Wrap|Line Numbers
  1. SELECT tblSTMT.STID, 
  2.        qrySendEM.CustID, 
  3.        qrySendEM.ACCT, 
  4.        qrySendEM.APCEmail, 
  5.        qrySendEM.STMTAP, 
  6.        tblSTMT.STDATE, 
  7.        tblSTMT.STMTPATH
  8. FROM tblSTMT 
  9. INNER JOIN qrySendEM 
  10. ON tblSTMT.ACCT = qrySendEM.ACCT
  11. WHERE (((qrySendEM.ACCT)=[Enter Acct]) 
  12. AND ((tblSTMT.STDATE)=[Enter Statement Date]));
Jan 7 '19 #3
twinnyfo
3,653 Recognized Expert Moderator Specialist
I notice that you are also using an embedded query for some of the data. I am not certain about this, but I think trying to build that Query from within the OpenRecordset may not work as expected. Perhaps post that query's SQL also?

I always recommend building such Queries as a SQL statement within VBA, then open the resultant string:

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. Dim db As DAO.Database
  3. Dim rst As DAO.Recordset
  4.  
  5. strSQL = _
  6.     "SELECT tblSTMT.STID, " & _
  7.         "qrySendEM.CustID, " & _
  8.         "qrySendEM.ACCT, " & _
  9.         "qrySendEM.APCEmail, " & _
  10.         "qrySendEM.STMTAP, " & _
  11.         "tblSTMT.STDATE, " & _
  12.         "tblSTMT.STMTPATH " & _
  13.     "FROM tblSTMT " & _
  14.     "INNER JOIN qrySendEM " & _
  15.     "ON tblSTMT.ACCT = qrySendEM.ACCT " & _
  16.     "WHERE (((qrySendEM.ACCT)=[Enter Acct]) " & _
  17.     "AND ((tblSTMT.STDATE)=[Enter Statement Date]));"
  18. Set db = CurrentDB()
  19. Set rst = db.OpenRecordset (strSQL)
  20.  
  21. ... etc.
This also better allows you to troubleshoot your SQL, as you can send it to the Immediate Window to see if the Query actually says what you want it to say.

Hope this hepps.
Jan 7 '19 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: jimatqsi | last post by:
I'm looking for information about compatibility between Access 2013 and Access 2003. I've been approached by a firm that wants to begin upgrading their systems. I want to know if it is reasonable...
0
by: LeoVBNET | last post by:
Hi Because VS 2013 dropped SQL COMPACT databases, I need to convert Access 2013 databases into SQL COMPACT in order to be able to use Linq to SQL in VB 2013. Anybody can help me? Thanks
6
by: GKJR | last post by:
I have been using Access 2013 (in Office 365) with Windows 8.1 for about a month and a half now. I was a little reluctant to switch from 2010 on Windows 7, but I figured I should try stay ahead of...
1
by: msilva100 | last post by:
Is it possible to split a Runtime MS Access 2013 database? I am on a Windows 7 server. I have one license of MS Access 2013. But I would like distribute this application to 5 client workstations. ...
1
by: msilva100 | last post by:
I need to have a UPC-A Barcode Add-In with MS Access runtime application. Has anyone ever used a Barcode Add-In with MS Access? Can someone share their runtime experience using Barcode Add-In....
4
by: jimatqsi | last post by:
A form I created that uses tabs seems to work fine on my development machine (Access 2007, fully patched). But two users that have Access 2013 runtime installed cannot see the tabs. They can see and...
7
by: jalbright1957 | last post by:
We have Office365 / Sharepoint online / Exchange online in our organization. I am the only one with the E3 subscription which gives me Access. I have a database that needs to be made available to...
1
by: tallen | last post by:
ADezii and zmbd, I have one other question. There seems to be some other code which possibly should reflect the new DAO code. the following does not allow forms to open any longer and files were...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.