473,433 Members | 2,051 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,433 software developers and data experts.

select sql dynamic query problem

Hi!
the following sql is identical to code in another database of mine. in
the first database it works perfectly, that is to say it writes the
query and I have a form based on the query. in the current database
the same sql when u base a form or report on it or indeed simply open
it, comes up with a box with the restration on it asking for a
perameter if you put the same registration no it works ok. baffled!

Dim rec As Recordset
Dim qdf As QueryDef
Dim strsql

Set db = CurrentDb
db.QueryDefs.Refresh
For Each qdf In db.QueryDefs
If qdf.Name = "qryWeightsTotals" Then
db.QueryDefs.Delete qdf.Name
End If
Next qdf

strsql = "SELECT [Date],[makemodel],pao, Street,[town],
[Postcode],[gross weight],tare,[net(kg)] FROM tblVanDetails WHERE
[RegistrationNo] = " & zz & ";"

End If
Set qdf = db.CreateQueryDef("qryWeightsTotals",
strsql) '
db.QueryDefs.Refresh
Me.Refresh
Set db = Nothing

I'm also trying to get it to total on the [net(kg)] field but that is
of secondary importance.
any help would be much appreciated.
Thanks in advance
Phil

Aug 28 '07 #1
8 1919
On Aug 28, 9:17 am, Philip_coll...@lineone.net wrote:
Hi!
the following sql is identical to code in another database of mine. in
the first database it works perfectly, that is to say it writes the
query and I have a form based on the query. in the current database
the same sql when u base a form or report on it or indeed simply open
it, comes up with a box with the restration on it asking for a
perameter if you put the same registration no it works ok. baffled!

Dim rec As Recordset
Dim qdf As QueryDef
Dim strsql

Set db = CurrentDb
db.QueryDefs.Refresh
For Each qdf In db.QueryDefs
If qdf.Name = "qryWeightsTotals" Then
db.QueryDefs.Delete qdf.Name
End If
Next qdf

strsql = "SELECT [Date],[makemodel],pao, Street,[town],
[Postcode],[gross weight],tare,[net(kg)] FROM tblVanDetails WHERE
[RegistrationNo] = " & zz & ";"

End If
Set qdf = db.CreateQueryDef("qryWeightsTotals",
strsql) '
db.QueryDefs.Refresh
Me.Refresh
Set db = Nothing

I'm also trying to get it to total on the [net(kg)] field but that is
of secondary importance.
any help would be much appreciated.
Thanks in advance
Phil
If you open up a form immediately after doing this then perhaps Access
is going through either the parsing phase or the optimization phase on
the new querydef and causing a timing issue. I believe that such
operations run asynchronously. That's where I'd look first. It also
explains why it works in one database and not in another.

James A. Fortune
CD********@FortuneJames.com

Aug 28 '07 #2
On 28 Aug, 20:13, CDMAPos...@FortuneJames.com wrote:
On Aug 28, 9:17 am, Philip_coll...@lineone.net wrote:


Hi!
the following sql is identical to code in another database of mine. in
the first database it works perfectly, that is to say it writes the
query and I have a form based on the query. in the current database
the same sql when u base a form or report on it or indeed simply open
it, comes up with a box with the restration on it asking for a
perameter if you put the same registration no it works ok. baffled!
Dim rec As Recordset
Dim qdf As QueryDef
Dim strsql
Set db = CurrentDb
db.QueryDefs.Refresh
For Each qdf In db.QueryDefs
If qdf.Name = "qryWeightsTotals" Then
db.QueryDefs.Delete qdf.Name
End If
Next qdf
strsql = "SELECT [Date],[makemodel],pao, Street,[town],
[Postcode],[gross weight],tare,[net(kg)] FROM tblVanDetails WHERE
[RegistrationNo] = " & zz & ";"
End If
Set qdf = db.CreateQueryDef("qryWeightsTotals",
strsql) '
db.QueryDefs.Refresh
Me.Refresh
Set db = Nothing
I'm also trying to get it to total on the [net(kg)] field but that is
of secondary importance.
any help would be much appreciated.
Thanks in advance
Phil

If you open up a form immediately after doing this then perhaps Access
is going through either the parsing phase or the optimization phase on
the new querydef and causing a timing issue. I believe that such
operations run asynchronously. That's where I'd look first. It also
explains why it works in one database and not in another.

James A. Fortune
CDMAPos...@FortuneJames.com- Hide quoted text -

- Show quoted text -
Thanks for the reply!
end of previous db code.
Set qdf = dbs.CreateQueryDef("qryCallHistory", strsql)

DoCmd.OpenForm "frmcallhistory"
Set dbs = Nothing
error handling. etc

on the current code I'm using another event??
at the risk of repeating myself. Baffled! I have spent several
fruitless hours searching help files of vaious descriptions.

Aug 28 '07 #3
Ben
On Aug 28, 6:17 am, Philip_coll...@lineone.net wrote:
Hi!
the following sql is identical to code in another database of mine. in
the first database it works perfectly, that is to say it writes the
query and I have a form based on the query. in the current database
the same sql when u base a form or report on it or indeed simply open
it, comes up with a box with the restration on it asking for a
perameter if you put the same registration no it works ok. baffled!

Dim rec As Recordset
Dim qdf As QueryDef
Dim strsql

Set db = CurrentDb
db.QueryDefs.Refresh
For Each qdf In db.QueryDefs
If qdf.Name = "qryWeightsTotals" Then
db.QueryDefs.Delete qdf.Name
End If
Next qdf

strsql = "SELECT [Date],[makemodel],pao, Street,[town],
[Postcode],[gross weight],tare,[net(kg)] FROM tblVanDetails WHERE
[RegistrationNo] = " & zz & ";"

End If
Set qdf = db.CreateQueryDef("qryWeightsTotals",
strsql) '
db.QueryDefs.Refresh
Me.Refresh
Set db = Nothing

I'm also trying to get it to total on the [net(kg)] field but that is
of secondary importance.
any help would be much appreciated.
Thanks in advance
Phil
Make sure that your "zz" is a number format and that the
registrationno is also a number format, otherwise it will need more
quotes.

Aug 28 '07 #4
On 28 Aug, 21:44, Ben <bmarl...@gmail.comwrote:
On Aug 28, 6:17 am, Philip_coll...@lineone.net wrote:


Hi!
the following sql is identical to code in another database of mine. in
the first database it works perfectly, that is to say it writes the
query and I have a form based on the query. in the current database
the same sql when u base a form or report on it or indeed simply open
it, comes up with a box with the restration on it asking for a
perameter if you put the same registration no it works ok. baffled!
Dim rec As Recordset
Dim qdf As QueryDef
Dim strsql
Set db = CurrentDb
db.QueryDefs.Refresh
For Each qdf In db.QueryDefs
If qdf.Name = "qryWeightsTotals" Then
db.QueryDefs.Delete qdf.Name
End If
Next qdf
strsql = "SELECT [Date],[makemodel],pao, Street,[town],
[Postcode],[gross weight],tare,[net(kg)] FROM tblVanDetails WHERE
[RegistrationNo] = " & zz & ";"
End If
Set qdf = db.CreateQueryDef("qryWeightsTotals",
strsql) '
db.QueryDefs.Refresh
Me.Refresh
Set db = Nothing
I'm also trying to get it to total on the [net(kg)] field but that is
of secondary importance.
any help would be much appreciated.
Thanks in advance
Phil

Make sure that your "zz" is a number format and that the
registrationno is also a number format, otherwise it will need more
quotes.- Hide quoted text -

- Show quoted text -
do you declare it as an
integer?

Aug 28 '07 #5
On Aug 28, 4:54 pm, Philip_coll...@lineone.net wrote:
...
Thanks again for your interest end of currenent db code
Set qdf = db.CreateQueryDef("qryWeightsTotals",
strsql) '
db.QueryDefs.Refresh
Me.Refresh
Set db = Nothing
error handling etc
i then use the qury later?
this is what baffles me!
Thanks very much for your interest.
Regards
Phil
By programming in a delay, the idea is that an adequate delay gives
Access time to do any housekeeping on the QueryDef so that query is
ready for the form to use as its RecordSource. If the change I
recommend doesn't solve the problem try a DoEvents loop. If that
doesn't solve the problem then it's quite unlikely that timing is the
cause of the problem and you need to look elsewhere. Usually a
parameter prompt is a result of a misspelled field name, but if the
code is the same as that in the database that works, it rules that
out. Maybe you put 'restration' in instead of 'registration.' If it
turns out that the zz is not the problem, as suggested by Ben, you can
also print the query string out to a file before copying and pasting
the text into the Query By Example (QBE) window.

James A. Fortune
CD********@FortuneJames.com

Aug 28 '07 #6
On 28 Aug, 21:59, Philip_coll...@lineone.net wrote:
On 28 Aug, 21:44, Ben <bmarl...@gmail.comwrote:


On Aug 28, 6:17 am, Philip_coll...@lineone.net wrote:
Hi!
the following sql is identical to code in another database of mine. in
the first database it works perfectly, that is to say it writes the
query and I have a form based on the query. in the current database
the same sql when u base a form or report on it or indeed simply open
it, comes up with a box with the restration on it asking for a
perameter if you put the same registration no it works ok. baffled!
Dim rec As Recordset
Dim qdf As QueryDef
Dim strsql
Set db = CurrentDb
db.QueryDefs.Refresh
For Each qdf In db.QueryDefs
If qdf.Name = "qryWeightsTotals" Then
db.QueryDefs.Delete qdf.Name
End If
Next qdf
strsql = "SELECT [Date],[makemodel],pao, Street,[town],
[Postcode],[gross weight],tare,[net(kg)] FROM tblVanDetails WHERE
[RegistrationNo] = " & zz & ";"
End If
Set qdf = db.CreateQueryDef("qryWeightsTotals",
strsql) '
db.QueryDefs.Refresh
Me.Refresh
Set db = Nothing
I'm also trying to get it to total on the [net(kg)] field but that is
of secondary importance.
any help would be much appreciated.
Thanks in advance
Phil
Make sure that your "zz" is a number format and that the
registrationno is also a number format, otherwise it will need more
quotes.- Hide quoted text -
- Show quoted text -

do you declare it as an
integer?- Hide quoted text -

- Show quoted text -
Sorry to be dense.you mean the strsql?
Thanks
Phil.

Aug 28 '07 #7
On 28 Aug, 21:44, Ben <bmarl...@gmail.comwrote:
On Aug 28, 6:17 am, Philip_coll...@lineone.net wrote:


Hi!
the following sql is identical to code in another database of mine. in
the first database it works perfectly, that is to say it writes the
query and I have a form based on the query. in the current database
the same sql when u base a form or report on it or indeed simply open
it, comes up with a box with the restration on it asking for a
perameter if you put the same registration no it works ok. baffled!
Dim rec As Recordset
Dim qdf As QueryDef
Dim strsql
Set db = CurrentDb
db.QueryDefs.Refresh
For Each qdf In db.QueryDefs
If qdf.Name = "qryWeightsTotals" Then
db.QueryDefs.Delete qdf.Name
End If
Next qdf
strsql = "SELECT [Date],[makemodel],pao, Street,[town],
[Postcode],[gross weight],tare,[net(kg)] FROM tblVanDetails WHERE
[RegistrationNo] = " & zz & ";"
End If
Set qdf = db.CreateQueryDef("qryWeightsTotals",
strsql) '
db.QueryDefs.Refresh
Me.Refresh
Set db = Nothing
I'm also trying to get it to total on the [net(kg)] field but that is
of secondary importance.
any help would be much appreciated.
Thanks in advance
Phil

Make sure that your "zz" is a number format and that the
registrationno is also a number format, otherwise it will need more
quotes.- Hide quoted text -

- Show quoted text -
It cant be in a number format as its vehicle registrations. when you
sy more quotes where exactly?
regards
Phil

Aug 29 '07 #8
On 28 Aug, 22:22, Philip_coll...@lineone.net wrote:
On 28 Aug, 21:59, Philip_coll...@lineone.net wrote:


On 28 Aug, 21:44, Ben <bmarl...@gmail.comwrote:
On Aug 28, 6:17 am, Philip_coll...@lineone.net wrote:
Hi!
the following sql is identical to code in another database of mine. in
the first database it works perfectly, that is to say it writes the
query and I have a form based on the query. in the current database
the same sql when u base a form or report on it or indeed simply open
it, comes up with a box with the restration on it asking for a
perameter if you put the same registration no it works ok. baffled!
Dim rec As Recordset
Dim qdf As QueryDef
Dim strsql
Set db = CurrentDb
db.QueryDefs.Refresh
For Each qdf In db.QueryDefs
If qdf.Name = "qryWeightsTotals" Then
db.QueryDefs.Delete qdf.Name
End If
Next qdf
strsql = "SELECT [Date],[makemodel],pao, Street,[town],
[Postcode],[gross weight],tare,[net(kg)] FROM tblVanDetails WHERE
[RegistrationNo] = " & zz & ";"
End If
Set qdf = db.CreateQueryDef("qryWeightsTotals",
strsql) '
db.QueryDefs.Refresh
Me.Refresh
Set db = Nothing
I'm also trying to get it to total on the [net(kg)] field but that is
of secondary importance.
any help would be much appreciated.
Thanks in advance
Phil
Make sure that your "zz" is a number format and that the
registrationno is also a number format, otherwise it will need more
quotes.- Hide quoted text -
- Show quoted text -
do you declare it as an
integer?- Hide quoted text -
- Show quoted text -

Sorry to be dense.you mean the strsql?
Thanks
Phil.- Hide quoted text -

- Show quoted text -
thank you both very much for your patient help. ben gave me a clue
when he spoke about more quotes, works fine now thans again!
regards
Phil

Aug 29 '07 #9

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

Similar topics

14
by: CJM | last post by:
I have a query which produces different results in the Access query builder and in an ASP page (via ADO) An example of the query is: ----------------------------------------------------------...
0
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the...
0
by: JB | last post by:
Hey ppl, I'm experiancing a very weird problem with my current Win32(win2k/XP) application. I'm using: * Delphi 7 * ADO * mySQL ODBC 3.51 drivers
2
by: Wei Wang | last post by:
Hi, I want to do a select in dynamic command, something like: TRIGGER FUNCTION DECLARE table_name_suffix text; temp_result RECORD; temp_result2 RECORD;
4
by: Chris | last post by:
Can't seem to figure out how to do this and have been reading for some time now...... I want to select a row count from a table name in SYSTABLES. This statement does not return what I needed,...
3
by: Michael McGrew | last post by:
I have a Dynamic drop-down box that is populated based on a ADO query. This works fine. I want to capture the users selection and assign it to a variable for use in another query. I am using the...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
2
by: paulmitchell507 | last post by:
I think I am attempting a simple procedure but I just can't figure out the correct syntax. My asp (classic) page runs a SELECT query to obtain dates and ID's from 2 tables uSQL = "SELECT...
6
by: jeddiki | last post by:
Hi, I am stuck again over something silly that I can not resolve. I am using a link to create a dynamic page. the link is itself written from the same same table that the dynamic page is...
45
by: dizzydangler | last post by:
Hi, I'm new to access (2007, running on XP), but I've gotten some great help from this site on my project so far. However, the more I know, the more complex the problems seem to become.... I'm...
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
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...
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
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...
0
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: 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...
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.