473,545 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Urgent VB SQL help!!!

6 New Member
Looking for some help urgently with some VB SQL Access stuff. You'll have to excuse the messiness of the code, I'm a newbie at all this. I'm running this code with a selection of check boxes to select extra fields for my table that is then exported to Excel. there are 3 fields that are always part of the SQL, when these are selected it works fine, however when I select any of the optional fields I get a Runtime Error '3011' saying:

the Microsoft Jet database engine could not find the object "

and that's it, no other clues at all as to where the problem could be in the code and I'm stuck! Any help would be greatly appreciated.

Code follows:

Private Sub lblEC_Click()

Dim EC As ADODB.Connectio n
Set EC = CurrentProject. Connection

'Dim ECRecordSet As New ADODB.Recordset
'ECRecordSet.Ac tiveConnection = EC

Dim x
Dim TABLESQL As String
Dim ECSQL As String

'DoCmd.Hourglas s True

On Error Resume Next
DoCmd.DeleteObj ect acTable, "tblResults "
On Error GoTo 0

'Table creation SQL

TABLESQL = "CREATE TABLE tblResults ([Date] DATETIME, [ProductionVolum e] LONG, [Usage] LONG"
If chkBudgetUsage Then TABLESQL = TABLESQL & ", [BudgetUsage] LONG"
If chkActualCost Then TABLESQL = TABLESQL & ", [ActualCost] CURRENCY"
If chkBudgetCost Then TABLESQL = TABLESQL & ", [BudgetCost] CURRENCY"
TABLESQL = TABLESQL & ") "
CurrentDb.Execu te TABLESQL

'Query SQL

ECSQL = "INSERT INTO tblResults ([Date], [ProductionVolum e], [Usage]"
If chkBudgetUsage Then ECSQL = ECSQL & ", [BudgetUsage]"
If chkActualCost Then ECSQL = ECSQL & ", [ActualCost]"
If chkBudgetCost Then ECSQL = ECSQL & ", [BudgetCost]"
ECSQL = ECSQL & ") "
ECSQL = ECSQL & "SELECT DISTINCT tblAccounting.D ate, tblProduction.P roductionVolume , Sum(tblReading. ReadingVolume) AS [Usage]"
If chkBudgetUsage Then ECSQL = ECSQL & ", tblBudget.Budge t AS BudgetUsage "

'Else
' ECSQL = ECSQL & ", 0 AS BudgetUsage "
'End If

If chkActualCost Then ECSQL = ECSQL & ", Sum([tblreading].[readingvolume]*[tbltariff].[tariff]) AS ActualCost"

'Else
' ECSQL = ECSQL & ", 0 as ActualCost "
'End If

If chkBudgetCost Then ECSQL = ECSQL & ", Sum([tblbudget].[budget]*[tblTariff].[Tariff]) AS BudgetCost"

'Else
' ECSQL = ECSQL & ", 0 as BudgetCost"
'End If

ECSQL = ECSQL & "FROM tblUtility INNER JOIN ((tblPeriod INNER JOIN ((tblAccounting INNER JOIN (tblProduction INNER JOIN tblBudget ON tblProduction.D epartmentID = tblBudget.Depar tmentID) ON (tblAccounting. Date = tblProduction.D ate) AND (tblAccounting. Date = tblBudget.Date) ) INNER JOIN (tblReading INNER JOIN tblMeter ON tblReading.Mete rID = tblMeter.MeterI D) ON tblAccounting.D ate = tblReading.Date ) ON tblPeriod.Perio d = tblAccounting.P eriod) INNER JOIN tblTariff ON tblPeriod.Perio d = tblTariff.Perio d) ON (tblUtility.Uti lityID = tblTariff.Utili tyID) AND (tblUtility.Uti lityID = tblMeter.Utilit yID) AND (tblUtility.Uti lityID = tblBudget.Utili tyID) "

Select Case Frame40
Case 1
'last 7 days
ECSQL = ECSQL & "GROUP BY tblAccounting.D ate, tblProduction.P roductionVolume , tblBudget.Budge t, tblProduction.D epartmentID, tblUtility.Util ityID "
ECSQL = ECSQL & "HAVING tblAccounting.D ate > #" & Format(Date - 7, "dd/mm/yyyy") & "#"
Case 2
'period to date
ECSQL = ECSQL & "GROUP BY tblAccounting.D ate, tblProduction.P roductionVolume , tblBudget.Budge t, tblProduction.D epartmentID, tblUtility.Util ityID "
ECSQL = ECSQL & "HAVING tblAccounting.p eriod = " & DLookup("period ", "tblAccounting" , "date=#" & Format(Date, "dd/mmm/yyyy") & "#")
Case 3
'ytd
ECSQL = ECSQL & "GROUP BY tblAccounting.D ate, tblProduction.P roductionVolume , tblBudget.Budge t, tblProduction.D epartmentID, tblUtility.Util ityID "
ECSQL = ECSQL & "HAVING right(tblAccoun ting.period,2) = " & Right(DLookup(" period", "tblAccounting" , "date=#" & Date & "#"), 2)
Case 4
'date range
ECSQL = ECSQL & "GROUP BY tblAccounting.D ate, tblProduction.P roductionVolume , tblBudget.Budge t, tblProduction.D epartmentID, tblUtility.Util ityID "
ECSQL = ECSQL & "HAVING tblAccounting.D ate BETWEEN #" & txtStart & "# AND #" & txtEnd & "#"
End Select
ECSQL = ECSQL & " AND ((tblProduction .DepartmentID)= 1) AND ((tblUtility.Ut ilityID)=1)"

'ECRecordSet.Op en ECSQL

CurrentDb.Execu te ECSQL
Dim output As String

output = "d:\mpl\Utiliti es\Database(2)\ Database\Depart ment\charts.xls "

DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel8, "tblResults ", output, False

'x = Shell(output, vbMaximizedFocu s)

x = Shell("c:\progr am files\microsoft office\office11 \excel.exe d:\mpl\Utilitie s\Database(2)\D atabase\Departm ent\charts.xls" , vbMaximizedFocu s)

Dim Xl As Excel.Applicati on
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet

Set Xl = CreateObject("E xcel.applicatio n")
Set XlBook = GetObject(outpu t)

Xl.Visible = True
XlBook.Windows( 1).Visible = True

1 Set XlSheet = XlBook.Workshee ts(1)

'XlSheet.Range( "a1").CopyFromR ecordset ECRecordSet
'Windows("outpu t.xls").Activat e
'Sheets("Graphi calAnalysis").S elect

'ECRecordSet.Cl ose

'Xl.Close

Set EC = Nothing
Set Xl = Nothing
Set XlBook = Nothing
Set XlSheet = Nothing
Set ECRecordSet = Nothing
Set EC = Nothing
'DoCmd.Hourglas s False
End Sub


Exuse the comments and stuff.

A swift response would be appreciated!!

Cheers

JP :confused:
Jul 11 '06 #1
4 3242
sashi
1,754 Recognized Expert Top Contributor
Hi Jonathan,

when you get this "Microsoft Jet database engine could not find the object" error it means one of the the table name is not found in your database.. pls check your line of code again and make sure the correct table name is specified.. good luck my fren.. :)

just make sure that these table names are correct and exist in your SQL database..

tblResults
tblAccounting
tblProduction
tblReading
tblBudget
tblTariff
tblUtility
tblPeriod
tblMeter
Jul 11 '06 #2
JonathanParker
6 New Member
Thanks for that, all those tables are in the database and they are all in the SQL too. when the error message comes up it's not for a ", it's for ' ' with no space between them. I've been through the code a number of times now and the only way I can make it work is by doing the following:

outputpath = "d:\mpl\Utiliti es\Database(2)\ Database\Depart ment\charts.xls "
Sheet = "Results"
DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel8, "tblResults ", outputpath, False, (Sheet)

There is one major issue with this though. When the query is run more than 5 or 6 times the same error message appears. Is there a limit or a hidden cache or something that needs to be emptied as part of the code?? Again, a swift response would be appreciated, I'm racking my brain trying to sort this out and it nearly has me beaten!!
Jul 11 '06 #3
sashi
1,754 Recognized Expert Top Contributor
Hi Jonathan,

i see.. it's something to do with the single quote.. well.. let me check your SQL statements line by line.. it's gonna take time buddy.. :)

well.. as far as i know there are no restriction to number of times a particular query can be executed.. let me check that part for you as well.. take care.. have a great day buddy.. :)
Jul 11 '06 #4
JonathanParker
6 New Member
You'll have to excuse me, I'm new to all this programming stuff, I've manged to go from having no knowledge at all 4 weeks ago to writing that stuff I posted. I'm getting the hang of it but the basics keep tripping me up, need some good programming etiquette!! Thanks for the help here, really appreciated!!
Jul 11 '06 #5

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

Similar topics

2
6365
by: Edwinah63 | last post by:
Hi Everyone, All the very best for 2004!! i need urgent help with this problem, the users are about to skin me alive!! we have an access front end with linked to sql server 2k tables. when a user tries to insert a record into one of the tables it
1
2498
by: Jenny | last post by:
Need urgent help for an unsolved problem. In our ASP web application, we creat a Back button and if user click on this button, it execute history.go(-1) to go back to the previous page. All our users use IE 6.0 and most of them don't have problem with this button. But one user reported everytime he click on this button, there is a pop-up...
8
1810
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error for some of my web application users but not others??? Even though the application runs from a central webserver??? Thanks for any help... Error: -----
6
2453
by: varkey.mathew | last post by:
Dear all, Bear with me, a poor newbie(atleast in AD).. I have to authenticate a user ID and password for a user as a valid Active Directory user or not. I have created the IsAuthenticated function exactly as outlined in the below link. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT02.asp
7
7226
by: zeyais | last post by:
Here is my HTML: <style> ..leftcolumn{float:left;width:300px;border: 1px solid #ccc} ..rtcolumn{float:left;width:600px;border: 1px solid #ccc} </style> <body> <div class="leftcolumn" id="d_links"> multiple <a href="hello.aspx?q=something">something</a><a href="hello.aspx?q=something1">something1</a><a
0
1888
by: bprasanth_20 | last post by:
Hi, I need an urgent help. I need to create a UDF (User Defined Function) in DB2 SQL which can accept any number of arguments (from 2 to 5 arguments). I do not how to achieve this. When I pass 2 arguments to the function (please note that it is not a procedure), it should return one value, if u pass 3 arguments, it should give another value and...
1
2152
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include <string>
1
1540
by: Domini | last post by:
Hi all, I need urgent help with an xml issue. Let me explain the scenario: My VB.NET app needs to read an xml (e.g. Sales Orders). This xml contains say 10 sales orders. Next the app needs to split the original xml into 10 individual SalesOrder xml files, each file containing a single sales order. The xml files created must be created based on a...
0
2567
by: Christopher | last post by:
Urgent Help Needed: The EPVH-1.1 Visual Hull Library. Dear All, I am a student doing research in computer vision. The EPVH-1.1 Visual Hull Library will really help a lot in my research. I did have this library before but I didn't keep my copy of this library because I always thought I could download it again form internet. However, the...
5
3535
by: koonda | last post by:
Hi all, I am a student and I have a project due 20th of this month, I mean May 20, 2007 after 8 days. The project is about creating a Connect Four Game. I have found some code examples on the internet which helped me little bit. But there are lot of problems I am facing developing the whole game. I have drawn the Board and the two players can...
0
7401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7808
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7423
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7757
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5329
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.