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

not quite right

The following code correctly creates the string and if I paste this into a
query it works everytime. It doesnt work though with the query Exists
function in as much that if the query is already there the set querydefs
part of the code doesnt update the sql so I get the string from when it ran
previously.

If I delete the query everytime then the createquerydef part works.

I am not sure why. regards in advance

peter

vba follows:

Private Sub Command4_Click()

Dim db As DAO.Database
Dim qdfTemp As DAO.QueryDef
Dim strSQL As String

Dim varItems As Variant
Dim strSelect As String
Dim strWhere As String
Dim strMods As String
Set db = CurrentDb
strSelect = "SELECT CDate(Format(DOSMBK.Date," & """d/m/yy" & """))" & " AS
DateDisp, DOSMBK.[DOSM-DSName]" & " FROM DOSMBK"

For Each varItems In Me.ListDOS.ItemsSelected

If strMods = vbNullString Then
strMods = "=" & """" & Me.ListDOS.Column(1, varItems) & """"
Else
strMods = strMods & " Or (DOSMBK.[DOSM-DSName])=" & """" &
Me.ListDOS.Column(1, varItems) & """"
End If

Next varItems

strWhere = " WHERE (((DOSMBK.[DOSM-DSName])" & (strMods) & "));"
strSQL = strSelect & strWhere
If Not QueryExists("Qrygetdosmodulebookings") Then
Set qdfTemp = db.CreateQueryDef("Qrygetdosmodulebookings", strSQL)
DoCmd.OpenQuery "Qrygetdosmodulebookings"
Set qdf = Nothing
Set db = Nothing
Else
Set qdfTemp = db.QueryDefs("Qrygetdosmodulebookings")
DoCmd.OpenQuery "Qrygetdosmodulebookings"
Set qdf = Nothing
Set db = Nothing
End If

'On Error Resume Next

'Debug.Print strSQL

End Sub
Nov 13 '05 #1
4 1206
My apologies AGAIN i thought I had tagged this to my original question! of
yesterday.

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ch**********@news7.svr.pol.co.uk...
The following code correctly creates the string and if I paste this into a
query it works everytime. It doesnt work though with the query Exists
function in as much that if the query is already there the set querydefs
part of the code doesnt update the sql so I get the string from when it ran previously.

If I delete the query everytime then the createquerydef part works.

I am not sure why. regards in advance

peter

vba follows:

Private Sub Command4_Click()

Dim db As DAO.Database
Dim qdfTemp As DAO.QueryDef
Dim strSQL As String

Dim varItems As Variant
Dim strSelect As String
Dim strWhere As String
Dim strMods As String
Set db = CurrentDb
strSelect = "SELECT CDate(Format(DOSMBK.Date," & """d/m/yy" & """))" & " AS DateDisp, DOSMBK.[DOSM-DSName]" & " FROM DOSMBK"

For Each varItems In Me.ListDOS.ItemsSelected

If strMods = vbNullString Then
strMods = "=" & """" & Me.ListDOS.Column(1, varItems) & """"
Else
strMods = strMods & " Or (DOSMBK.[DOSM-DSName])=" & """" &
Me.ListDOS.Column(1, varItems) & """"
End If

Next varItems

strWhere = " WHERE (((DOSMBK.[DOSM-DSName])" & (strMods) & "));"
strSQL = strSelect & strWhere
If Not QueryExists("Qrygetdosmodulebookings") Then
Set qdfTemp = db.CreateQueryDef("Qrygetdosmodulebookings", strSQL)
DoCmd.OpenQuery "Qrygetdosmodulebookings"
Set qdf = Nothing
Set db = Nothing
Else
Set qdfTemp = db.QueryDefs("Qrygetdosmodulebookings")
DoCmd.OpenQuery "Qrygetdosmodulebookings"
Set qdf = Nothing
Set db = Nothing
End If

'On Error Resume Next

'Debug.Print strSQL

End Sub

Nov 13 '05 #2
If Not QueryExists("Qrygetdosmodulebookings") Then
Set qdfTemp = db.CreateQueryDef("Qrygetdosmodulebookings", strSQL)
Else
Set qdfTemp = db.QueryDefs("Qrygetdosmodulebookings")
qdfTemp = strSQL
End If
qdfTemp.Execute
Set qdf = Nothing
Set db = Nothing

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ch**********@news7.svr.pol.co.uk...
The following code correctly creates the string and if I paste this into a
query it works everytime. It doesnt work though with the query Exists
function in as much that if the query is already there the set querydefs
part of the code doesnt update the sql so I get the string from when it ran previously.

If I delete the query everytime then the createquerydef part works.

I am not sure why. regards in advance

peter

vba follows:

Private Sub Command4_Click()

Dim db As DAO.Database
Dim qdfTemp As DAO.QueryDef
Dim strSQL As String

Dim varItems As Variant
Dim strSelect As String
Dim strWhere As String
Dim strMods As String
Set db = CurrentDb
strSelect = "SELECT CDate(Format(DOSMBK.Date," & """d/m/yy" & """))" & " AS DateDisp, DOSMBK.[DOSM-DSName]" & " FROM DOSMBK"

For Each varItems In Me.ListDOS.ItemsSelected

If strMods = vbNullString Then
strMods = "=" & """" & Me.ListDOS.Column(1, varItems) & """"
Else
strMods = strMods & " Or (DOSMBK.[DOSM-DSName])=" & """" &
Me.ListDOS.Column(1, varItems) & """"
End If

Next varItems

strWhere = " WHERE (((DOSMBK.[DOSM-DSName])" & (strMods) & "));"
strSQL = strSelect & strWhere
If Not QueryExists("Qrygetdosmodulebookings") Then
Set qdfTemp = db.CreateQueryDef("Qrygetdosmodulebookings", strSQL)
DoCmd.OpenQuery "Qrygetdosmodulebookings"
Set qdf = Nothing
Set db = Nothing
Else
Set qdfTemp = db.QueryDefs("Qrygetdosmodulebookings")
DoCmd.OpenQuery "Qrygetdosmodulebookings"
Set qdf = Nothing
Set db = Nothing
End If

'On Error Resume Next

'Debug.Print strSQL

End Sub

Nov 13 '05 #3
Interestingly it comes up with an error on the qdfTemp = strSQL part I thing
it said it couldnt evaluate.

:(

"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:lG********************@twister01.bloor.is.net .cable.rogers.com...
If Not QueryExists("Qrygetdosmodulebookings") Then
Set qdfTemp = db.CreateQueryDef("Qrygetdosmodulebookings", strSQL) Else
Set qdfTemp = db.QueryDefs("Qrygetdosmodulebookings")
*******************qdfTemp = strSQL***********************
End If
qdfTemp.Execute
Set qdf = Nothing
Set db = Nothing

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ch**********@news7.svr.pol.co.uk...
The following code correctly creates the string and if I paste this into a query it works everytime. It doesnt work though with the query Exists
function in as much that if the query is already there the set querydefs
part of the code doesnt update the sql so I get the string from when it

ran
previously.

If I delete the query everytime then the createquerydef part works.

I am not sure why. regards in advance

peter

vba follows:

Private Sub Command4_Click()

Dim db As DAO.Database
Dim qdfTemp As DAO.QueryDef
Dim strSQL As String

Dim varItems As Variant
Dim strSelect As String
Dim strWhere As String
Dim strMods As String
Set db = CurrentDb
strSelect = "SELECT CDate(Format(DOSMBK.Date," & """d/m/yy" & """))" & "

AS
DateDisp, DOSMBK.[DOSM-DSName]" & " FROM DOSMBK"

For Each varItems In Me.ListDOS.ItemsSelected

If strMods = vbNullString Then
strMods = "=" & """" & Me.ListDOS.Column(1, varItems) & """"
Else
strMods = strMods & " Or (DOSMBK.[DOSM-DSName])=" & """" &
Me.ListDOS.Column(1, varItems) & """"
End If

Next varItems

strWhere = " WHERE (((DOSMBK.[DOSM-DSName])" & (strMods) & "));"
strSQL = strSelect & strWhere
If Not QueryExists("Qrygetdosmodulebookings") Then
Set qdfTemp = db.CreateQueryDef("Qrygetdosmodulebookings", strSQL) DoCmd.OpenQuery "Qrygetdosmodulebookings"
Set qdf = Nothing
Set db = Nothing
Else
Set qdfTemp = db.QueryDefs("Qrygetdosmodulebookings")
DoCmd.OpenQuery "Qrygetdosmodulebookings"
Set qdf = Nothing
Set db = Nothing
End If

'On Error Resume Next

'Debug.Print strSQL

End Sub


Nov 13 '05 #4
Sorry: my fault.

That should be qdfTemp.SQL = strSQL

As well, I just realized that using qdfTemp.Execute isn't going to work, as
you've only got a SELECT query (the Execute method only works with Action
queries). However, once you're saved the SQL in the new query,
DoCmd.OpenQuery "Qrygetdosmodulebookings" should work.
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ch**********@newsg3.svr.pol.co.uk...
Interestingly it comes up with an error on the qdfTemp = strSQL part I thing it said it couldnt evaluate.

:(

"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:lG********************@twister01.bloor.is.net .cable.rogers.com...
If Not QueryExists("Qrygetdosmodulebookings") Then
Set qdfTemp = db.CreateQueryDef("Qrygetdosmodulebookings", strSQL)
Else
Set qdfTemp = db.QueryDefs("Qrygetdosmodulebookings")
*******************qdfTemp = strSQL***********************
End If
qdfTemp.Execute
Set qdf = Nothing
Set db = Nothing

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ch**********@news7.svr.pol.co.uk...
The following code correctly creates the string and if I paste this into a
query it works everytime. It doesnt work though with the query Exists
function in as much that if the query is already there the set
querydefs part of the code doesnt update the sql so I get the string from when
it ran
previously.

If I delete the query everytime then the createquerydef part works.

I am not sure why. regards in advance

peter

vba follows:

Private Sub Command4_Click()

Dim db As DAO.Database
Dim qdfTemp As DAO.QueryDef
Dim strSQL As String

Dim varItems As Variant
Dim strSelect As String
Dim strWhere As String
Dim strMods As String
Set db = CurrentDb
strSelect = "SELECT CDate(Format(DOSMBK.Date," & """d/m/yy" & """))" &
" AS
DateDisp, DOSMBK.[DOSM-DSName]" & " FROM DOSMBK"

For Each varItems In Me.ListDOS.ItemsSelected

If strMods = vbNullString Then
strMods = "=" & """" & Me.ListDOS.Column(1, varItems) & """"
Else
strMods = strMods & " Or (DOSMBK.[DOSM-DSName])=" & """" &
Me.ListDOS.Column(1, varItems) & """"
End If

Next varItems

strWhere = " WHERE (((DOSMBK.[DOSM-DSName])" & (strMods) & "));"
strSQL = strSelect & strWhere
If Not QueryExists("Qrygetdosmodulebookings") Then
Set qdfTemp = db.CreateQueryDef("Qrygetdosmodulebookings",

strSQL) DoCmd.OpenQuery "Qrygetdosmodulebookings"
Set qdf = Nothing
Set db = Nothing
Else
Set qdfTemp = db.QueryDefs("Qrygetdosmodulebookings")
DoCmd.OpenQuery "Qrygetdosmodulebookings"
Set qdf = Nothing
Set db = Nothing
End If

'On Error Resume Next

'Debug.Print strSQL

End Sub



Nov 13 '05 #5

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

Similar topics

4
by: Michael | last post by:
But i'm a good c++ programmer. What i want to do is parse a text file and store the information in relevant fields: //Text File: *Version 200 *SCENE { AMBIENT_COLOUR 0.0 0.0 0.0
10
by: Andrzej Kaczmarczyk | last post by:
Hi C# gurus :) I have a conversion problem. I have a class that I can't change - it's a DataColumn class; I have a wrapper class around it. public MyDataColumn : DataColumn {
5
by: gooderthanyou | last post by:
Alright i've looked a ton of topics and most of them are unresolved... configure: error: Cannot find MySQL header files under usr/local/mysql. Note that the MySQL client library is not bundled...
5
by: junkmailblackhole | last post by:
I am building a website that is having problems displaying the navbar in IE 6. The URL is http://www.cleanbrain.com. When the page initially loads it looks just the way I want it. However, when the...
2
by: Greg Buchholz | last post by:
/* I've been experimenting with some generic/polytypic programs, and I've stumbled on to a problem that I can't quite figure out. In the program below, I'm trying to define a generic version of...
23
by: Anton Vredegoor | last post by:
I'm trying to import text from an open office document (save as .sxw and read the data from content.xml inside the sxw-archive using elementtree and such tools). The encoding that gives me the...
8
by: Steve K. | last post by:
I want to have AutoSuggest based on a database (or webservice) query. So as the user types say... a last name I will make an async call to a service to get matches, then set the suggestion list at...
1
by: David24 | last post by:
my best attempt to get the following code to store 2 ints representing the average location of x and y coordinates is throwing NullExeption errors. this is unsafe C# code by the way. i'm a novice so...
10
by: dandyliondancer | last post by:
hola i figured out how to make an image appear next to a link when hovering by displaying it as a block and then using background:url div.menu a{ display:block; } div.menu a:hover{
17
by: liketofindoutwhy | last post by:
to simply add two quote images around some text. seems quite simple at first but turns out all the obvious solutions are not as desirable as a perfect solution: please see...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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
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...

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.