473,715 Members | 6,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Constant Date Parameter in VBA Code

Hello'
I have a table with a column for each year.
I have a form that will be writing a date (from a cbo in a form) to
these columns.
I am trying to write a IF statement that will update these columns
depending on the year.
i.e. if the chosen date is in 2008, it will write to the 2008 column,
if 2009, the 2009 column...

Iv'e tried a couple different ways, but canot seem to get it to work.
The following code will write to the the first column, then try the
second but then gets halted as the qrydef get's duplicated or
something. Which leads me to beleive that the way I am writing the IF
parameter in the code is incorrect.

I want the code to run through these IF statements & write to the
appropriate column based on the year. The table's year columns are
formatted as 'Med Date', as is the cbobox these dates are coming
from.

(the strSQL line of code works fine on it's own..it's just the IF
statements I can't get to work)

If Forms![frmTraining_Sel ection]![cboCompDate] >= 1 / 1 / 7 <= 12 /
31 / 7 Then

strSQL = "UPDATE tblNext_and_Dat es SET tblNext_and_Dat es.[2007] =
Forms![frmTraining_Sel ection]![cboCompDate] Where [tblNext_and_Dat es].
[Training Name]=Forms![frmTraining_Sel ection]![Training Name] AND
tblNext_and_Dat es.[Employee Name] IN(" & strCriteria & ");"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryCompDat e"
Set db = Nothing
Set qdf = Nothing
End If

If Forms![frmTraining_Sel ection]![cboCompDate] >= 1 / 1 / 8 <= 12 /
31 / 8 Then

strSQL = "UPDATE tblNext_and_Dat es SET tblNext_and_Dat es.[2008] =
Forms![frmTraining_Sel ection]![cboCompDate] Where [tblNext_and_Dat es].
[Training Name]=Forms![frmTraining_Sel ection]![Training Name] AND
tblNext_and_Dat es.[Employee Name] IN(" & strCriteria & ");"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryCompDat e"
Set db = Nothing
Set qdf = Nothing
End If

FYI: I'm using Access 2000 SP2. Any Ideas?
Jan 8 '08 #1
2 3868
ry***********@g mail.com wrote:
Hello'
I have a table with a column for each year.
I have a form that will be writing a date (from a cbo in a form) to
these columns.
I am trying to write a IF statement that will update these columns
depending on the year.
i.e. if the chosen date is in 2008, it will write to the 2008 column,
if 2009, the 2009 column...

Iv'e tried a couple different ways, but canot seem to get it to work.
The following code will write to the the first column, then try the
second but then gets halted as the qrydef get's duplicated or
something. Which leads me to beleive that the way I am writing the IF
parameter in the code is incorrect.

I want the code to run through these IF statements & write to the
appropriate column based on the year. The table's year columns are
formatted as 'Med Date', as is the cbobox these dates are coming
from.

(the strSQL line of code works fine on it's own..it's just the IF
statements I can't get to work)

If Forms![frmTraining_Sel ection]![cboCompDate] >= 1 / 1 / 7 <= 12 /
31 / 7 Then

strSQL = "UPDATE tblNext_and_Dat es SET tblNext_and_Dat es.[2007] =
Forms![frmTraining_Sel ection]![cboCompDate] Where [tblNext_and_Dat es].
[Training Name]=Forms![frmTraining_Sel ection]![Training Name] AND
tblNext_and_Dat es.[Employee Name] IN(" & strCriteria & ");"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryCompDat e"
Set db = Nothing
Set qdf = Nothing
End If

If Forms![frmTraining_Sel ection]![cboCompDate] >= 1 / 1 / 8 <= 12 /
31 / 8 Then

strSQL = "UPDATE tblNext_and_Dat es SET tblNext_and_Dat es.[2008] =
Forms![frmTraining_Sel ection]![cboCompDate] Where [tblNext_and_Dat es].
[Training Name]=Forms![frmTraining_Sel ection]![Training Name] AND
tblNext_and_Dat es.[Employee Name] IN(" & strCriteria & ");"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryCompDat e"
Set db = Nothing
Set qdf = Nothing
End If

FYI: I'm using Access 2000 SP2. Any Ideas?
Dim datComp As Date
datComp = Cdate(Forms![frmTraining_Sel ection]![cboCompDate])
If datComp >= #1/1/07# And datComp <= #12/31/07# Then

Korn
http://www.youtube.com/watch?v=k4X0JohCzsQ
Jan 8 '08 #2
Perfect!

On Jan 8, 10:20*am, Salad <o...@vinegar.c omwrote:
ryan.paque...@g mail.com wrote:
Hello'
I have a table with a column for each year.
I have a form that will be writing a date (from a cbo in a form) to
these columns.
I am trying to write a IF statement that will update these columns
depending on the year.
i.e. if the chosen date is in 2008, it will write to the 2008 column,
if 2009, the 2009 column...
Iv'e tried a couple different ways, but canot seem to get it to work.
The following code will write to the the first column, then try the
second but then gets halted as the qrydef get's duplicated or
something. Which leads me to beleive that the way I am writing the IF
parameter in the code is incorrect.
I want the code to run through these IF statements & write to the
appropriate column based on the year. The table's year columns are
formatted as 'Med Date', as is the cbobox these dates are coming
from.
(the strSQL line of code works fine on it's own..it's just the IF
statements I can't get to work)
If Forms![frmTraining_Sel ection]![cboCompDate] >= 1 / 1 / 7 <= 12 /
31 / 7 Then
* *strSQL = "UPDATE tblNext_and_Dat es SET tblNext_and_Dat es.[2007]=
Forms![frmTraining_Sel ection]![cboCompDate] Where [tblNext_and_Dat es].
[Training Name]=Forms![frmTraining_Sel ection]![Training Name] AND
tblNext_and_Dat es.[Employee Name] IN(" & strCriteria & ");"
* *qdf.SQL = strSQL
* *DoCmd.OpenQuer y "qryCompDat e"
* *Set db = Nothing
* *Set qdf = Nothing
* *End If
If Forms![frmTraining_Sel ection]![cboCompDate] >= 1 / 1 / 8 <= 12 /
31 / 8 Then
* *strSQL = "UPDATE tblNext_and_Dat es SET tblNext_and_Dat es.[2008]=
Forms![frmTraining_Sel ection]![cboCompDate] Where [tblNext_and_Dat es].
[Training Name]=Forms![frmTraining_Sel ection]![Training Name] AND
tblNext_and_Dat es.[Employee Name] IN(" & strCriteria & ");"
* *qdf.SQL = strSQL
* *DoCmd.OpenQuer y "qryCompDat e"
* *Set db = Nothing
* *Set qdf = Nothing
* *End If
FYI: I'm using Access 2000 SP2. Any Ideas?

Dim datComp As Date
datComp = Cdate(Forms![frmTraining_Sel ection]![cboCompDate])
If datComp >= #1/1/07# And datComp <= #12/31/07# Then

Kornhttp://www.youtube.com/watch?v=k4X0Joh CzsQ- Hide quoted text -

- Show quoted text -
Jan 8 '08 #3

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

Similar topics

5
3733
by: Dominique Javet | last post by:
Hello, I'm new to php and mysql and I use Dreamweaver MX 2004, so sorry for this "newbie" question... I've found no answer in the forum ... I've a date problem with my formular. In my mysql DB my filed "date" in table "experience" is like this: Y-m-d (2002-07-23). My fied`date` is date, NOT NULL with no default entry My form read well the date data depending the id, (pe. 30.02.2003), but when I submit a new date, I receive as result...
8
3151
by: Tony Johansson | last post by:
Hello Experts! What does this mean actually. If you have a template with a type and non-type template argument, say, like this template<typename T, int a> class Array {. . .}; then A<int, 1> and A<int, 2> are different types. Now, if the A template
11
5293
by: lovecreatesbeauty | last post by:
Hello experts, Is const_cast only applied to pointers or references? If I have a constant object, then how can I remove constant attribute from it? #include <vector> #include <string> using namespace std;
5
1884
by: DataB | last post by:
Hi everyone, I have this piece of VBA script: ' checking the DOB field to see if we constrain on the date If Len(Me.EmpDOBTxt & "") > 0 Then strWhere = strWhere & " AND . <= #" & Me.DOBTxt & "#" End If
10
6874
by: John Austin | last post by:
I am migrating my first vb6 app to vb.net 2003. In the vb6 app a number of subs had optional date parameters: Sub Fred ( ... ,optional FromDate as Date = 0...) I need something like zero in there to see if the parameter has been used or not. In vb.net the imported code fails with: Value of type 'Integer' cannot be converted to 'Date'
6
4905
by: cipher | last post by:
I have some constant values in my web service that my client application will require. Having to keep server side and client side definitions insync is tedious. I am trying to do something like this: public __value enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 }; However, the resulting wsdl omits the actual flag values: - <s:simpleType name="Colors">
6
35669
by: fctk | last post by:
hello, i'm trying to compile this small program: int main(void) { unsigned long int max; max = 4000000000;
7
3169
by: icosahedron | last post by:
Is there a way to determine if a parameter to a function is a constant (e.g. 2.0f) versus a variable? Is there some way to determine if this is the case? (Say some metaprogramming tip or type trait?) I have a function with an if statement, that I would like to optimize away somehow. I was hoping the compiler would do it for me, but it doesn't seem to. Jay
6
1474
by: Mark Weedon | last post by:
I'm sure this is insanely obvious... but i can't figure it out. I have a db that organises applications for an event. Included in the applicant information is their date of birth. On a form or report i can calculate and display their current age (=(DateDiff("d",,Date()))/365) and also their age at the time (=(DateDiff("d",,"28/07/07"))/365) of the event. As you can see i'm using a hardcoded date for the event date so i have to change...
0
8821
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
8718
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9340
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...
1
9103
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,...
1
6646
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
5967
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
4477
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
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
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.