473,394 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

VBA - Getting 3011 when trying to run query

Hi all,
This is my first post, well, ever...
So here it goes.

I'm writing a chunk of code that finds an email address in a table, then places it into the SendObject method.

When I try to run it I get the dreaded 3011.
Please help.

Ps. I only got this far thanks to people's posts and your responses. So thanks so much for that =)

Here's the code:
Expand|Select|Wrap|Line Numbers
  1. Dim strTo As String
  2. Dim rst As dao.Recordset
  3. Dim dbs As Database
  4. Dim strSQL As String
  5. Dim strtablename As String
  6.  
  7. strtablename = "Branches"
  8.  
  9. Set dbs = CurrentDb()
  10.  
  11. strSQL = "SELECT Email_Address AS EmailAddress FROM " & strtablename & " WHERE Branch_Code= " & TempVars("SelectedBranch").Value
  12.  
  13. ' The above SQL is all one line, so there's no need to put any underscores
  14. ' I also tried Branches.[Email Address] and [Email Address]
  15.  
  16. Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenTable)
  17.  
  18.  
  19. DoCmd.SendObject acSendQuery, bla bla bla, strTo, , , bla bla bla
  20.  
-------------------------

the funny thing is, when I use this SQL in a query in access, it works fine. When I put it in the openrecordset in VBA, I get the 3011.

Expand|Select|Wrap|Line Numbers
  1. (
  2. SELECT Branches.[Email Address]
  3. FROM Branches
  4. WHERE (((Branches.[Branch Code])=112));
  5. )
FYI. 112 is replaced with tempvar.value

Any help would be appreciated.
Much thanks, peace and love
Nov 6 '07 #1
7 2446
Rabbit
12,516 Expert Mod 8TB
take out the dbOpenTable parameter, you're not opening a table.
Nov 6 '07 #2
Ah!
thanks so much, that fixed it. Actually, turns out my query had a bug in it as well.
However, another problem has risen.
You see, the document I am sending (excel sheet from query) has Arabic characters in it.
When I export it from a macro (and in the access tables/queries) it looks fine.
Once it's in the vba code, however, I get rubbish.
Any tips?
Nov 7 '07 #3
Rabbit
12,516 Expert Mod 8TB
Hmm, this one I don't know about. Since this is essentially a different question, try posting a new thread, maybe someone else will have encountered this before.
Nov 7 '07 #4
No worries.
I actually bypassed the code entirely and did it in a macro.
The sendobject macro allows you to have a textbox value inserted into the TO: field but not a query result.
What I did was turn the form into a query, and cycle through the email records, all the while grabbing the email address from a hidden text box.
Dirty, but works very well.
thanks for your help Rabbit
and sorry about the extra post.
Nov 8 '07 #5
Rabbit
12,516 Expert Mod 8TB
Not a problem, good luck.

If that works and you want to know the code, you can convert all your macros to VBA code and then take a look at that.
Nov 8 '07 #6
Hi Rabbit,
Sorry, just saw your post.
Thanks. That was very helpful and will be for the future.
Nov 27 '07 #7
Rabbit
12,516 Expert Mod 8TB
Not a problem, good luck.
Nov 27 '07 #8

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

Similar topics

1
by: Trevor Best | last post by:
Just been having this problem when Exporting a query. DoCmd.TransferText acExportDelim, "GenMESR Export Specification", "qryGenMESRExport", Environ$("TEMP") & "\MESR.CSV", False I get the...
4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
3
by: Praetorian Prefect | last post by:
Code will not work in XP. Any ideas? Public Sub GetData() ' Declare variables Dim InputDir, ImportFile As String, tblName As String, strsql As String InputDir = ("f:\") ImportFile =...
2
by: enough2Bdangerous | last post by:
Access database (file format 2002-2003) generates reports with docmd.openreport but returns 3011 runtime error related to the printer. Switching Windows default printer is a work around but need to...
3
by: enough2Bdangerous | last post by:
access runtime error 3011 on docmd.openreport -------------------------------------------------------------------------------- Access database (file format 2002-2003) generates reports with...
1
by: Bhavesh Devgan | last post by:
Hi all, am having a runtime error while exportnig data by running a query through TransferSpreadsheet command Error it shows: object could not be found 'Select * from where . =200704 The...
0
by: Dirk.Emmermacher | last post by:
Hello list. I' ve got a problem with mde files from Office XP. We have following situation: We are running a W2K Terminal server with an Office XP. There is a Access application running (mde...
2
by: xmanin | last post by:
i have developed some functions in module using which i want to download CSV files from a Stock exchange server. everything is fine but i am unable to download CSV file, i get following msg "3011 The...
4
by: forrestgump | last post by:
In my access database I have created vba which deletes information in a table and then uploads a .txt file based on it's naming convention. However if you specific an incorrect naming convention...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.