473,670 Members | 2,574 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 1297
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.OpenR ecordset("Selec t 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
2968
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 attempting to perform a "left join" query to build a cross-reference table. The left join query is currently taking nearly 2 hours for MySQL to process, using Navicat as a front-end. My system specs are 1.4Mhz Pentium Processor with 1GB of RAM...
7
6197
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 make it better soon. Unfortunately, there is never a non-crucial time in which we can do an upgrade, so we are stuck for now. Point 1: There are multiple tables: students, courses, cross-reference
9
1498
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 to either manually write down the values from the watch window, or break the code, write a custom procedure to print the values for me, then run the code to the breakpoint again. By now, though, my library of collection-oriented tools makes such...
3
1414
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 the table are not related in any way. I want to loop through each record in the query, find matching records in the table and delete them. The code counts the correct number of records
3
2932
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 groups for years, I figure it's time for me to contribute a little bit back, maybe some people out there will find this useful. * Introduction This is a "how-to" style article, showing by example how to dynamically
17
3404
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 it's "On Click" Event proceedure to Loop through my Database and find any records that fall within a Certain Date...if a record is found...it then emails me that a record
4
5234
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. The file I'm searching is in a data farm so I'm stuck with using it in its present format. Linking to the file or importing it as a local table have no effect on speed. How can I get this code to perform quicker?
3
1943
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 has logged in. I set a loggedin session in the log in page, which I have tested and works fine in other scripts. I am displaying news on the homepage (which is stored in a mysql database), and this works fine when the user accesses the homepage...
2
2444
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 book using similar methods, but I'm having some trouble with using the class functions (I'm new to OOP in PHP 5). So far I've written a Contact Book class and a Contact class. The Contact Book class has add, edit, delete and display functions for...
0
960
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 some code which will allow me to do it but i dont know how to change the code. Could someone please help me. I have added the code for you to. function MyQuery::OnClick(eventObj) { // Get the default SQL command for the form. var...
0
8466
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...
1
8591
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7412
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
6212
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
5683
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4208
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
4388
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
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

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.