473,508 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CODE FOR QUERY?

hey guys,

Could someone please provide me with some code that would peform the
following:
I need a query to be done everytime the Database is opened that checks
a field "DueDate", if the current Date falls between the two months
prior to the "DueDate", then it will run a command that I have written,
titled "command38", this command button can be found on each record, so
if the dueDate is within the next two months then I want to database to
execute this command38! any suggestions?

Jun 1 '06 #1
1 1292
If you want to stay with macros - you can use the Autoexec macro. This
macro executes only when An Access mdb is opened. You can create this
macro by opening a new macro in the macro window - choosing what
commands you want it to run and then just save the macro with the name

Autoexec

That is how you create an Autoexec macro. In the macro designer - you
have a dropdown with several selections of stuff you can perform.

If you want to use VBA, you can use the Access StartUp properties - go
to the Tools Menu/Startup and select a form to open. When the form
opens you can write some code in the Form_Open event or Form_load event
to do stuff like check your DueDate. Here is how you would do that.

First, I assume DueDate is a field in a table with some date and that is
the only field in that table and there is only one row/one column which
contains this duedate (if that is not the case - you need to change your
application so that it is the case - this is the conventional way to
store a unique date). In the Form_Load event you can write code like
this:

Private Sub Form_Load()
Dim RS As DAO.Recordset
Set RS = CurrentDB.OpenRecordset("Select DueDate From yourTable")

If DateDiff("m", RS(0), Date) < 2 Then
'do something - send an email, flag something...
End If
End Sub

RS is a recordset object. You set it to the table that contains your
Date Info. RS(0) refers to the first field in the table - 0 refers to
the ordinal number of the first field (everythings starts with 0 in VB).
If a table has more than one field then RS(0) is the first field, RS(1)
is the second field. RS.Fields.Count will return the normal count of
all the fields in a table.

Note: If a table has 10 fields, RS.Fields.Count returns 10. But if you
want to reference the field count in a For Looop, you have to subtract
one column because the counter starts at 0 -- 0 to 9 (10 fields)
0,1,2,3,4,5,6,7,8,9

For i = 0 to RS.Fields.Count - 1
'--Do something
Next

HTH
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 1 '06 #2

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

Similar topics

4
2962
by: DBNovice | last post by:
I have a database that keeps records on the issue and failure of an item. Currently, the database is poorly desisned; therefore I'm performing queries to break the data into normalized tables and...
7
6169
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
9
1487
by: Steve Jorgensen | last post by:
First, an example - today, I wanted to print out the parameter values in a querydef object at a break point in the code for subsequent manual debugging of the query. In the past, I would have had...
3
1408
by: White Bilky | last post by:
A97. Simplified description: I have a query which returns one field containing numbers. I have a table where one field contains the same numbers as the query (amongst others). The query and...
3
2923
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news...
17
3377
by: Liam.M | last post by:
Hey guys, Forgive me if my question my be alittle silly, but I would very much appreciate and assistance that could be given! My situation is as follows: I have created a Button, and set...
4
5214
by: Rick | last post by:
Access2003 in XP I'm using the code below to append any new records from (tbl_From_Mainframe) into (tbl_Appended_Data). It takes more than a minute to search 7000 records for a dozen new records....
3
1930
by: Hazza | last post by:
Hi, I am using PHP and mysql to create a website. I am fairly new to PHP, and thus am grateful to anyone who helps! Firstly I am running a homepage, that displays additional content if a user...
2
2437
by: chromis | last post by:
Hi there, I've been reading an OOP book recently and it gives some nice Adaptor / Template patttern code to wrap around the php Mysql functions. I thought that I'd try and create a Simple Address...
0
950
by: savage678 | last post by:
Hi Everyone, I am new to this forum and am i dire need of some help. I am trying to use wildcard searches in infopath. I have it connected to an access database using data connection. I have...
0
7398
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...
0
7502
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
5637
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,...
1
5057
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
4716
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
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
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 ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
bsmnconsultancy
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...

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.