473,785 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query builder vs. vba for timestamp criteria

EJO
In the query builder, I can create a query that will take a date/time
as criteria, and the query finds the records:

SELECT SRSrvcsEquip.St ock, SRSrvcsEquip.Ac tivity,
SRSrvcsEquip.Eq uipOwned, SRSrvcsEquip.Ma nufacturer, SRSrvcsEquip.EH SN,
SRSrvcsEquip.Qt y, SRSrvcsEquip.Pa rtNumber, SRSrvcsEquip.De scription,
SRSrvcsEquip.Li stType, SRSrvcsEquip.Si te_ID, SRSrvcsEquip.SR _ID,
SRSrvcsEquip.Li stDate, SRSrvcsEquip.ID
FROM SRSrvcsEquip
WHERE (((SRSrvcsEquip .ListDate)=#7/13/2006 10:25:0#));
Whereas this will not:

*************** *************** ********
Private Sub Command13_Click ()

Dim strSql As String, dtListDate As String, intListType As Integer,
intSR_ID As Integer, intSite_ID As Integer, strCriteria As String

dtListDate = Now
intListType = Me.OpenArgs
intSR_ID = Me.SR_ID
intSite_ID = Me.Site_ID

strSql = "INSERT INTO SRSrvcsEquip ( Activity, EquipOwned,
Manufacturer, EHSN, Qty, PartNumber, Description, Stock, ListType,
Site_ID, SR_ID, ListDate) SELECT [SRSrvcsEquipDef aults].[Activity],
[SRSrvcsEquipDef aults].[EquipOwned],
[SRSrvcsEquipDef aults].[Manufacturer], [SRSrvcsEquipDef aults].[EHSN],
[SRSrvcsEquipDef aults].[Qty], [SRSrvcsEquipDef aults].[PartNumber],
[SRSrvcsEquipDef aults].[Description], [SRSrvcsEquipDef aults].[Stock], "
& intListType & ", " & intSite_ID & ", " & intSR_ID & " AS SR, #" &
dtListDate & "# FROM SRSrvcsEquipDef aults WHERE
((([SRSrvcsEquipDef aults].[ListName])=[Forms]![OLSelect]![Combo1]))
ORDER BY [SRSrvcsEquipDef aults].[ID];"

strCriteria = "[SR_ID] = " & intSR_ID & " AND[ListType] = " &
intListType & " AND[ListDate] = #" & dtListDate & "#"

With DoCmd
.SetWarnings 0
.RunSQL strSql
.SetWarnings -1
.Close
.OpenForm "OLEdit", , , strCriteria, , , intListType
End With

End Sub

*************** *************** ***********
Private Sub Form_Open(Cance l As Integer)

Dim strSql As String, strListName As String, intSite_ID As Integer

DoCmd.Maximize
If IsNumeric(Me.Op enArgs) = True Then
strSql = "Select * From SRSrvcsEquip;"
Me.ListDate.Vis ible = True
Me.ListName.Vis ible = False
Me.txtSC.Visibl e = True
Me.txtSR.Visibl e = True
Me.Command22.Vi sible = True
Else
strSql = "SELECT * FROM SRSrvcsEquipDef aults Where " & Me.OpenArgs
& ";"
Me.ListDate.Vis ible = False
Me.ListName.Vis ible = True
Me.txtSC.Visibl e = False
Me.txtSR.Visibl e = False
Me.Command22.Vi sible = False
End If

Me.RecordSource = strSql

End Sub

*************** *************** ********
Instead of the records with the specific datetime, I get a recordset
without regard to the criteria and can't build the list to allow for
version control.

Thanks,

EJO

Jul 13 '06 #1
4 4035
EJO wrote:
In the query builder, I can create a query that will take a date/time
as criteria, and the query finds the records:

SELECT SRSrvcsEquip.St ock, SRSrvcsEquip.Ac tivity,
SRSrvcsEquip.Eq uipOwned, SRSrvcsEquip.Ma nufacturer, SRSrvcsEquip.EH SN,
SRSrvcsEquip.Qt y, SRSrvcsEquip.Pa rtNumber, SRSrvcsEquip.De scription,
SRSrvcsEquip.Li stType, SRSrvcsEquip.Si te_ID, SRSrvcsEquip.SR _ID,
SRSrvcsEquip.Li stDate, SRSrvcsEquip.ID
FROM SRSrvcsEquip
WHERE (((SRSrvcsEquip .ListDate)=#7/13/2006 10:25:0#));
Whereas this will not:

*************** *************** ********
Private Sub Command13_Click ()

Dim strSql As String, dtListDate As String, intListType As Integer,
intSR_ID As Integer, intSite_ID As Integer, strCriteria As String

dtListDate = Now
intListType = Me.OpenArgs
intSR_ID = Me.SR_ID
intSite_ID = Me.Site_ID

strSql = "INSERT INTO SRSrvcsEquip ( Activity, EquipOwned,
Manufacturer, EHSN, Qty, PartNumber, Description, Stock, ListType,
Site_ID, SR_ID, ListDate) SELECT [SRSrvcsEquipDef aults].[Activity],
[SRSrvcsEquipDef aults].[EquipOwned],
[SRSrvcsEquipDef aults].[Manufacturer], [SRSrvcsEquipDef aults].[EHSN],
[SRSrvcsEquipDef aults].[Qty], [SRSrvcsEquipDef aults].[PartNumber],
[SRSrvcsEquipDef aults].[Description], [SRSrvcsEquipDef aults].[Stock], "
& intListType & ", " & intSite_ID & ", " & intSR_ID & " AS SR, #" &
dtListDate & "# FROM SRSrvcsEquipDef aults WHERE
((([SRSrvcsEquipDef aults].[ListName])=[Forms]![OLSelect]![Combo1]))
ORDER BY [SRSrvcsEquipDef aults].[ID];"

strCriteria = "[SR_ID] = " & intSR_ID & " AND[ListType] = " &
intListType & " AND[ListDate] = #" & dtListDate & "#"

With DoCmd
.SetWarnings 0
.RunSQL strSql
.SetWarnings -1
.Close
.OpenForm "OLEdit", , , strCriteria, , , intListType
End With

End Sub

*************** *************** ***********
Private Sub Form_Open(Cance l As Integer)

Dim strSql As String, strListName As String, intSite_ID As Integer

DoCmd.Maximize
If IsNumeric(Me.Op enArgs) = True Then
strSql = "Select * From SRSrvcsEquip;"
Me.ListDate.Vis ible = True
Me.ListName.Vis ible = False
Me.txtSC.Visibl e = True
Me.txtSR.Visibl e = True
Me.Command22.Vi sible = True
Else
strSql = "SELECT * FROM SRSrvcsEquipDef aults Where " & Me.OpenArgs
& ";"
Me.ListDate.Vis ible = False
Me.ListName.Vis ible = True
Me.txtSC.Visibl e = False
Me.txtSR.Visibl e = False
Me.Command22.Vi sible = False
End If

Me.RecordSource = strSql

End Sub

*************** *************** ********
Instead of the records with the specific datetime, I get a recordset
without regard to the criteria and can't build the list to allow for
version control.

Thanks,

EJO
Open the code window for the form. To the left of the Docmd.Maximize
press the mouse button on the bar. A circle will appear. Now close the
form and run. When it hits the Maximize, it will step you through the
code. Most likely OpenArgs is numeric and you don't get a filtered list.

Also, you are passing intListType and not the Where clause string.

I think if you do some debugging you'll find the flaws in your logic.

Hint: I sometimes will enter a line like
msgbox strSQL
and when I run the code see if the sql with the where clause is what I
expect. I recommend you step through your code and use a couple of
msgboxes.
Jul 13 '06 #2
EJO
Open the code window for the form. To the left of the Docmd.Maximize
press the mouse button on the bar. A circle will appear. Now close the
form and run. When it hits the Maximize, it will step you through the
code. Most likely OpenArgs is numeric and you don't get a filtered list.

Also, you are passing intListType and not the Where clause string.

I think if you do some debugging you'll find the flaws in your logic.

Hint: I sometimes will enter a line like
msgbox strSQL
and when I run the code see if the sql with the where clause is what I
expect. I recommend you step through your code and use a couple of
msgboxes.
Thanks, Salad; i've debugged it time and again (even with the msgbox to
check the criteria, which is being passed via DoCmd.OpenForm) .
Everything but the recordset result is coming through as I expect.
When I take out the date/time portion, the results are as expected
given the remaining criteria. Mostly, I was hoping it was just
something I was overlooking.

I've even gone so far as to turn the criteria to have the date/time in
a range using dateadd(), -1 sec on the front and add 1 on the back:

strCriteria = "[SR_ID] = " & intSR_ID & " AND[ListType] = " &
intListType & " AND[ListDate] Between #" & DateAdd("s", -1,
dtListDate) & "# AND #" & DateAdd("s", 1, dtListDate) & "#"

Jul 14 '06 #3
EJO wrote:
>>Open the code window for the form. To the left of the Docmd.Maximize
press the mouse button on the bar. A circle will appear. Now close the
form and run. When it hits the Maximize, it will step you through the
code. Most likely OpenArgs is numeric and you don't get a filtered list.

Also, you are passing intListType and not the Where clause string.

I think if you do some debugging you'll find the flaws in your logic.

Hint: I sometimes will enter a line like
msgbox strSQL
and when I run the code see if the sql with the where clause is what I
expect. I recommend you step through your code and use a couple of
msgboxes.


Thanks, Salad; i've debugged it time and again (even with the msgbox to
check the criteria, which is being passed via DoCmd.OpenForm) .
Everything but the recordset result is coming through as I expect.
When I take out the date/time portion, the results are as expected
given the remaining criteria. Mostly, I was hoping it was just
something I was overlooking.

I've even gone so far as to turn the criteria to have the date/time in
a range using dateadd(), -1 sec on the front and add 1 on the back:

strCriteria = "[SR_ID] = " & intSR_ID & " AND[ListType] = " &
intListType & " AND[ListDate] Between #" & DateAdd("s", -1,
dtListDate) & "# AND #" & DateAdd("s", 1, dtListDate) & "#"
OK. Your SQL statement was large enough I didn't want to get involved
with it. However, I decided to drop it into a module and I got the
typical red line incorrect syntax error.

strSql = "INSERT INTO SRSrvcsEquip ( Activity, EquipOwned,
Manufacturer, EHSN, Qty, PartNumber, Description, Stock, ListType,
Site_ID, SR_ID, ListDate) SELECT [SRSrvcsEquipDef aults].[Activity],
[SRSrvcsEquipDef aults].[EquipOwned],
[SRSrvcsEquipDef aults].[Manufacturer], [SRSrvcsEquipDef aults].[EHSN],
[SRSrvcsEquipDef aults].[Qty], [SRSrvcsEquipDef aults].[PartNumber],
[SRSrvcsEquipDef aults].[Description], [SRSrvcsEquipDef aults].[Stock], "
& intListType & ", " & intSite_ID & ", " & intSR_ID & " AS SR, #" &
dtListDate & "# FROM SRSrvcsEquipDef aults WHERE
((([SRSrvcsEquipDef aults].[ListName])=[Forms]![OLSelect]![Combo1]))
ORDER BY [SRSrvcsEquipDef aults].[ID];"

Now, I decided that there were no underscore _'s so this must be
wordwrapped. So I put it onto 1 line. And it was still red-lined.

I noticed the quotes in the strSQL assignment and so I fixed it with dbl
quotes.

Since this statement, when executed, will add records, and you have
warnings off, maybe no records are being added and for whatever reason
you aren't getting an error.

Could you fix your statement with proper quote markings and then run
your code. It's a frigging PITA that you can't take a SQL statement
generated from the Query Builder and plop it into a variable. I hate
all the quotes that you sometimes need to add, chopping lines into parts
using the underscore, etc as you build a dynamic SQL statement. It's
too bad they didn't have an add-in tool to drop in a SQL statement and
have it correctly create the
strSQL = "...
statement that could be plugged into code. I can't imagine how many
1000's, maybe millions of manhours that have been spent by developers
worldwide fixing the statement that comes from the builder.

Now, I'm not saying that's the source of your error. But if no records
get added you certainly aren't going to find any.
Jul 14 '06 #4
* EJO:
>Open the code window for the form. To the left of the Docmd.Maximize
press the mouse button on the bar. A circle will appear. Now close the
form and run. When it hits the Maximize, it will step you through the
code. Most likely OpenArgs is numeric and you don't get a filtered list.

Also, you are passing intListType and not the Where clause string.

I think if you do some debugging you'll find the flaws in your logic.

Hint: I sometimes will enter a line like
msgbox strSQL
and when I run the code see if the sql with the where clause is what I
expect. I recommend you step through your code and use a couple of
msgboxes.

Thanks, Salad; i've debugged it time and again (even with the msgbox to
check the criteria, which is being passed via DoCmd.OpenForm) .
Everything but the recordset result is coming through as I expect.
When I take out the date/time portion, the results are as expected
given the remaining criteria. Mostly, I was hoping it was just
something I was overlooking.

I've even gone so far as to turn the criteria to have the date/time in
a range using dateadd(), -1 sec on the front and add 1 on the back:

strCriteria = "[SR_ID] = " & intSR_ID & " AND[ListType] = " &
intListType & " AND[ListDate] Between #" & DateAdd("s", -1,
dtListDate) & "# AND #" & DateAdd("s", 1, dtListDate) & "#"
Pardon my butting in here, but I think I see the problem. By resetting
the RecordSource in the Form_Open, you are clearing the form criteria.

Perhaps, you could simply add a filter in the Form_Open to get the
desired result? Or, perhaps you could add the criteria to the Insert
SQL that you are running in the previous form.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Jul 14 '06 #5

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

Similar topics

3
579
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to make a query that selects from a table as desribed below .. I have a table (Volunteer) that has a member field (memnumber) and a number of fields that are headed in various categories and are yes/no formated
2
535
by: NigelMThomas | last post by:
I have an especially challenging problem. I know there are a few geniuses in this group so perhaps; you can advise me whether or not this can be done as an update query in Access. Thanks. I am trying to join two tables if certain conditions are met § TaxID in Table 1 must match TaxID in Table 2 § DRG in Table 1 must match DRG in Table 2 § BeginDate in Table 1 must match BeginDate in Table 2 § If all these criteria are met and...
3
2881
by: Don Sealer | last post by:
I'm guessing this is pretty simple however not simple enough for me. I'm developing a database to track expenses, income, banking transactions, etc. I have a very simple query with four fields, date, checking account deposits, savings account deposits, savings account withdrawals. How do I get this query to only show dates when a transaction occurred in one of the other three fields? Thanks, Don..............
0
1998
by: sales | last post by:
I am glad to present to the community of this group the new version of our component intended for visual building of SQL queries via an intuitive interface - Active Query Builder (http://www.activequerybuilder.com/). It has full support for MS SQL Server dialect starting from version 7 to 2005. Active Query Builder can be used in different development environments. Today our visual component is availiable in the following editions:...
33
7671
by: Birky | last post by:
Can you please help me understand how to build Criteria syntax within the Query Builder? If you have a field that is for a region (lets say for Midwest) and you have another field which breaks it down into a smaller geographical region like City (lets say Denver) how can I build the Criteria within the Query Builder to key off a previous select field to narrow down the location? If region Midwest is select within region...
22
31211
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for June, and will return all records in that month.
3
2633
by: Thorben Grosser | last post by:
Hello Newsgroup, I am doing some archive database and therefore got one table indexing every folder and one table storing which rack belongs to which department, eg: table folders : +-----------+------+-------+ | folder_id | rack | date |
2
2114
by: Coll | last post by:
I have a form and a query. I would like to have some control on the form (check box probably), that when selected will limit the criteria for a field in a query. Here are the details.... When the checkbox (or whatever control is appropriate on the form) is checked, the field "employment_category" in my query will have the following criteria - not "temp" and not "diem" - I've tried several things, but I can't seem to figure out how to...
2
1781
by: iheartvba | last post by:
Hi, I usually use access query builder to create complex queries. Especially to create Sub Queries I.E. a querying another query. In my current situation I need to provide the criteria to the query from a Form and then call it using the rst function in ADO (see last line of my code). The issue with the rst function is that it doesn't cater for queries made in access query builder that have an object from a Form as their criteria. I have...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10325
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8972
agi2029
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...
1
7499
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
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.