473,385 Members | 1,615 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,385 software developers and data experts.

My query isn't updating....

Do I need to use the REQUERY method in my code below? The query strSQL isn't updating with new information when my variables change. Can someone help me with the correct code to "refresh" my query? Also, is my code correct for setting up a query? Thank you for your help!!

[code]
Private Sub comboExcelForVendor_AfterUpdate()
On Error GoTo Err_MyProc
Dim dbs As DAO.Database, qdf As DAO.QueryDef, strSQL As String
Set dbs = CurrentDb
Dim strTableName, strClient, strExcelName, strDate As String
Dim myPos


strTableName = Forms!frmDailyClient!comboExcelforVendor
myPos = InStr(1, strTableName, "_", vbTextCompare) - 1
strExcelName = Left(strTableName, myPos)
strDate = Right(strTableName, 7)

strSQL = "SELECT TOP 20" & strTableName & ".Symbol, " & strTableName & ".Cusip, " & strTableName & ".TotalQty FROM " & strTableName & " " & _
"GROUP BY " & strTableName & ".Symbol, " & strTableName & ".Cusip, " & strTableName & ".TotalQty, " & strTableName & ".ML_DailyRate " & _
"HAVING (((" & strTableName & ".ML_DailyRate) < 4.5 Or (" & strTableName & ".ML_DailyRate) = 4.5)) " & _
"ORDER BY " & strTableName & ".ML_SMV ASC;"

Set qdf = dbs.QueryDefs("qryCreateExcel")
'qdf.SQL = strSQL
qdf.Close

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryCreateExcel", "c:\documents and settings\Leslie\My Documents\Vodia Group\" & strExcelName & "\" & strExcelName & " Rate Request" & strDate & ".xls", True
MsgBox ("File successfully exported")
Set qdf = Nothing
Set dbs = Nothing

Exit_MyProc:
Set dbs = Nothing
Set qdf = Nothing
Exit Sub

Err_MyProc:
Resume Exit_MyProc

End Sub
Nov 9 '06 #1
6 1459
NeoPa
32,556 Expert Mod 16PB
The first bit of the SQL (SELECT TOP 20) is missing a space after the 20 - this may well cause a problem.
In SELECT queries with only one recordsource, it's not necessary to quote the source before each field.
It does no harm in the general course of events, but makes something like this more complicated than it needs (IMHO) to be.
As for the SQL - I can see nowhere that it's used so I'm unable to help with refreshing it I'm afraid.
Nov 9 '06 #2
Thank you for noticing the missing space! What I need this code to do is update the query qryCreateExcel each time my variable strTableName changes. Although my variable is changing, the expression strSQL isn't CHANGING qryCreateExcel. Any thoughts? Thanks!
Nov 9 '06 #3
Oh, I forgot...my TRANSFERSPREADSHEET command is using qryCreateExcel...should I forget about qryCreateExcel and use strSQL directly in the TRANSFER SPREADSHEET command. I thought I had to use a "legitimate" table or query in this command.
Nov 9 '06 #4
NeoPa
32,556 Expert Mod 16PB
Now we have some light on the problem.
Expand|Select|Wrap|Line Numbers
  1. Set qdf = dbs.QueryDefs("qryCreateExcel")
  2. 'qdf.SQL = strSQL
  3. qdf.Close
From your posted code, you have the important line removed by the comment character (') at the start the line.
Try removing the comment char.

If this concept is faulty (editing the SQL of a saved query) then create a new query instead with the SQL and just delete it when finished.
Nov 9 '06 #5
I have included my NEW code...I have changed the order and placement of some of my commandes and have changed my strSQL statement. Should I use the .CREATEQUERYDEF or just .QUERYDEF? Also, my code doesn't run and when I try to open qryCreateExcel, I get an error message #3122 "You tried to execute a query that does not include the specified expression variable name.ML_SMV as part of an aggregate function. Any thoughts? thanks!!!!!
Nov 9 '06 #6
I got it working! thank you for hanging in there with me!!!
Nov 9 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Phoenix | last post by:
Here's a challenge that is killing me: I've got 2 web servers and a SQL Server and about 5,000 'users' who stay connected to the site all day. I have a page that is supposed to be 'real-time',...
2
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An...
6
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
5
by: deko | last post by:
How to run action query against linked table? I have an Access 2003 mdb with an Excel 2003 Workbook as a linked table. When I attempt to run an action query against the linked table I get this...
1
by: David Sorber via AccessMonster.com | last post by:
Hello, I've got two questions. Im writing an Access 2000 database to collect data from multiple Visual Foxpro Databases, total some figures, save the data into a table for archiving purposes, and...
31
by: Lag | last post by:
Having a problem updating my database from a web page, through a submission form. Can anyone help? ----THIS IS MY CODE IN update.php----(user, pass, and database are typed in directly, I...
3
by: hharriel | last post by:
Hi All, I have created an update query related to high school course information (name of course; credit hour; course description, etc.) I am updating a master course information table. I am...
9
by: davek | last post by:
(posted to: php.general, comp.lang.php, alt.php, alt.php.sql) I have a form where registered users on my site can edit their login details. For some reason, the script is inserting an extraneous...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.