Howdy all. I have pretty much NO VB/Access coding experience, but am forced to come up with a generic script/process for users with varying database designs and varying levels of expertise to use and integrate into their Dbs.
Following is my script and is launched On_Open event. The script determines someone's desired upload class (test, archive or recent), executes a specific query based on that info, then writes the query results to a text file, tab-delimited. I am trying to use createQueryDef so that the query can be built on the fly with a temporary query - no need to make several permanent queries. As you might notice, the main problem is having to insert TOP 300 in the SQL query, the WHERE changes are quite manageable, the TOP 300 gets me.
Anyway, my diagnostic MsgBox right before the createQueryDef works, but I get stuck in some kinda error/hold after that, that requires ctrl+break to get out of.
Thanks for any insight!!! I am using Access 2000 right now, to ensure as much universal compatibility as possible, but that may be a mistake! -
Option Compare Database
-
-
Private Sub Report_Open(Cancel As Integer)
-
-
Dim uploadClass As Integer
-
Dim countDates As Integer
-
-
Set dbs = CurrentDb
-
Set rst = dbs.OpenRecordset("SELECT * FROM date_tracking")
-
-
If rst.RecordCount = 0 Then
-
response = MsgBox("Is this for a Test Upload?", vbYesNoCancel, "Upload Type")
-
If response = vbYes Then
-
uploadClass = 0
-
bp (uploadClass) 'run query and data export
-
ElseIf response = vbNo Then
-
response = MsgBox("Access will now generate an Archive upload.", vbOKCancel, "Upload Type")
-
If response = vbOK Then
-
uploadClass = 2
-
bp (uploadClass)
-
End If
-
End If
-
Else: response = MsgBox("Access will now generate an upload of new records since last.", vbOKCancel, "Upload Type")
-
If response = vbOK Then
-
uploadClass = 1
-
bp (uploadClass)
-
End If
-
End If
-
Set rst = Nothing
-
End Sub
-
-
Sub bp(uploadClass As Integer)
-
On Error GoTo bp_Err
-
-
Dim date_update As Integer
-
Dim fileName As String
-
Dim strTop As String
-
Dim strWhere As String
-
Dim strFields As String
-
Dim qryName As String
-
Dim strSQL As String
-
-
date_update = 1
-
-
'******** COPY AND PASTE FROM SQL VIEW OF Query *********
-
'----------------------------------------------------------------------------------------------------
-
-
strFields = " { copy & paste complex JOIN/ON/FROM query } "
-
-
'----------------------------------------------------------------------------------------------------
-
'*******************************************************************
-
-
If (uploadClass = 0) Then
-
strTop = "TOP 300 "
-
strWhere = " WHERE table1.date > Date()-1095 "
-
date_update = 2
-
ElseIf (uploadClass = 1) Then
-
strTop = ""
-
strWhere = " WHERE (((table1.date)<(SELECT Max([UploadDate]) AS maxDate FROM date_tracking;))) "
-
Else
-
strTop = ""
-
strWhere = " WHERE table1.date > Date()-1095 "
-
End If
-
-
strSQL = "SELECT " & strTop & strFields & strWhere
-
qryName = "bpQuery"
-
Set dbs = CurrentDb
-
response = MsgBox("I'm about to CreateQueryDef", vbOKOnly, "") ' for diagnostic purposes only
-
Set qdf = dbs.CreateQueryDef(qryName, strSQL)
-
response = MsgBox("I'm just went through CreateQueryDef", vbOKOnly, "") ' for diagnostic purposes only
-
Set qdf = Nothing
-
-
fileName = "C:/bp/" & DatePart("m", Date) & DatePart("d", Date) & DatePart("yyyy", Date) & ".txt"
-
DoCmd.OutputTo acOutputQuery, qryName, acFormatTXT, fileName, False, ""
-
' OR DoCmd.TransferText acExportDelim, "", qryName, fileName, False, ""
-
-
DoCmd.QueryDefs(qryName).delete
-
-
bp_Exit:
-
If date_update = 1 Then
-
Set rst = dbs.OpenRecordset("date_tracking")
-
rst.AddNew
-
rst![UploadDate] = Date - 1
-
rst.Update
-
rst.Close
-
End If
-
-
bp_Err:
-
date_update = 2
-
Resume bp_Exit
-
End Sub
-
Regards,
oh4real
2 2935
BTW, line 65-70 is where the createQueryDef is.
oh4real
Nevermind. Problems were at least 2-fold:
1) Tools -> References - were not all ticked, as per forum helpers! Don't remember which ones I ticked, so can't test if this was the original problem, but I think #2 is the real reason.
2) The QueryDefs.delet e qryName line had 'db' for database, while it should been 'dbs'. Therefore the query was never deleted - this caused a primary failure of the CreateQueryDef (qryName, strSql) since it couldn't overwrite.
3) The _Err & _Exit had not Exit Sub in them, so got unending loops - once did .addnew 245,000 times ;)
Clear head, great night's sleep and refill on Adderall go a long way...
Sorry to bother,
oh4real
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Andrew |
last post by:
Hi:
I run into the following problem where I would use CreateQuerydef to create
a new Table and then use "Execute" to execute the statement. However, I
keep getting an error message saying that the table already exists! (Error
3010 Table already exists). But I made sure that the table were dropped
before I executed the statement and I went into the database to check that
the table was deleted before I ran the "execute" statement. Here...
|
by: priscilla.jenkins |
last post by:
Alright, I'm really new to SQL and VBA and all this, so I might be
completely off course...but just tell me. I know C and Assembly, but
that doesn't help me much here.
I'm trying to create a module that creates 5 queries (that a report is
based on) based on a table that the user defines. My tables are named
by date (not my choice), for example:
-ArchivedActions05-20-05 Everything involving that seems fine.
I'm getting a syntax error...
|
by: Natt Serrasalmus |
last post by:
After years of operating without any coding standards whatsoever, the
company that I recently started working for has decided that it might be a
good idea to have some. I'm involved in this initiative.
Typically I find that coding standards are written by some guy in the
company who has a way of coding that he likes and then tries to force
everybody else to write code the way he likes it, not for any rational
reason, but simply for the...
|
by: R Reyes |
last post by:
Hello All,
I'm always looking for ways to improve my code. Most of the time (whenever
I'm working on a project) I write a bunch of functions. Then after the
project is finished, I put all the similar functions into their own
module/class/page for neatness:
-- like a stringsManipulate class which has all string manipulation methods
to the project...separated from the whole project into its own library for
neatness.
-- like a...
|
by: Jon Maz |
last post by:
Hi,
I am writing inline code .aspx pages using VS.Net 2002. The color coding
seems to work for VB.NET inline, and not for C# inline (see below).
Does anyone know how to get this working for C#?
TIA,
JON
| |
by: TJ Doherty |
last post by:
Need help understanding the following please:
When I am creating a project and code my connection using Dim connectString
As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data
Source=C:\Temp\NW-test.MDB", everything works correctly when I run the
project.
However, if I set up the exact same connection using the DataAdapter wizard
and try to run the project, I get a "Microsoft Jet database engine cannot
open the file..." error.
|
by: Electrified Research |
last post by:
I just want to know other peoples' views about this. Now that VS2005
is out, how do people feel about visual editors?
Personally I am so comfortable with hand coding that Visual Studio
along with other comparable tools seem to slow me down or just don't
provide enough value to what I'm doing. I truly hope I'm missing the
point and really want to discover something about Visual Studio that
makes me want to switch, but until then, I just...
|
by: Expat |
last post by:
I have several queries that I create from SQL statements using Currentdb.CreateQueryDef in one of these cases the code breaks and refuses to create the query giving me a:
Run-time error 3131. Syntax error in FROM clause. I'm supposing that it won't create the query because it analyzes the SQL string and determines that there is a syntax error in the FROM clause of the query I am trying to create.
The odd thing is that if I take this same SQL...
|
by: rahuldev999 |
last post by:
Hi
I am beginner in the access project.
can anyone suggest how to deal with this
" Set rq = Db.CreateQueryDef("r_temp_rslt_research", strSql)"
in the below code.As its a MDB application which needs to be converted into ADP.
Any kind of help would be highly appreciated.
Below is the snippet of code:
Dim Db As DAO.Database
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |