?
Solved

simple query and automatic date

Posted on 2003-03-18
11
Medium Priority
?
148 Views
Last Modified: 2010-05-03
How can I store the following query as a variable (the data contorl is datEmployee):

"Select [EmployeeNumber] from EMPLOYEE where [Position] = Customer Assistant"

How do I automatically get the current date in the format dd/mm/yyyy (i.e. 13/11/2003) and assign this to a variable. For example when i click invoice button on a form I want the depature date to be automatically set to the current date.
0
Comment
Question by:willgilmore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 1

Expert Comment

by:sazhagianambi
ID: 8158258
Hi,

dim dat as date
dat=Format(Date(),"dd/mm/yyyy")

After,

Select [EmployeeNumber] from EMPLOYEE where [Position] = Customer Assistant and Date=dat

This Will return the Result For Current Date.

Nambi
0
 
LVL 3

Expert Comment

by:DocM
ID: 8158267
Hy,

strQuery= "Select [EmployeeNumber] from EMPLOYEE where [Position] = Customer Assistant"

strDate = Format(Date, "dd/mm/yyyy")
 
0
 
LVL 1

Expert Comment

by:hazgod
ID: 8158406
the current date command is just date$

so you want to do:

dim thisDeparture as string

thisDeparture = (Select [EmployeeNumber] from EMPLOYEE where [Position] = Customer Assistant) & " " & date$

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 30

Expert Comment

by:Mayank S
ID: 8172400
You can capture the system date using the Now feautre provided by VB:

Dim current as Date

current = DateValue (CStr(Now))

This will put the system date in dd/mm/yyyy format into the 'current' variable.

You can use:

datEmployee.DatabaseName = "...." ' what-ever
datEmployee.RecordSource = "SELECT * FROM EMPLOYEE.... "
datEmployee.Refresh

With datEmployee.Recordset
  If .EOF Then
    MsgBox "No match found! "
  Else
    .Edit
    ![DepartureDate] = DateValue (CStr(Now))
' I'm assuming that DepartureDate is the name of the attribute
    .Update
  End If
End With


Hope that helps!

Mayank.

0
 
LVL 1

Expert Comment

by:hazgod
ID: 8173952
date$ is the system date function
0
 

Author Comment

by:willgilmore
ID: 8174083
Sorry this doesnt work.

Im trying to get the employee number of datEmployee where employee position = customer assistant. How do I store this result as a variable, accessing the data control. I used the above (EmployeePosition = Select [EmployeeNumber] from EMPLOYEE where [Position] = Customer Assistant) and got this:

Compile error
Syntax error


0
 
LVL 1

Expert Comment

by:hazgod
ID: 8174110
try doing

dim thisEmployeePos

Select [EmployeeNumber] from EMPLOYEE where [Position] = Customer Assistant)

thisEmployeePos= txtEmployeePosition

where does the date come in?
0
 

Author Comment

by:willgilmore
ID: 8174180
Ignore the date at this stage. I have tried the above code before, but it will not work. Do i have to include the datEmployee in the code. If doesnt know where EMPLOYEE table comes from.
0
 
LVL 1

Expert Comment

by:hazgod
ID: 8174433
if the employee position is a number then you will need to do

thisEmployeePos= val(txtEmployeePosition)

to get the number from the text box
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8178862
Try this:

"SELECT * FROM EMPLOYEE WHERE POSITION = 'CUSTOMER ASSISTANT' ; "

' Please notice the quotes around 'customer assistant', and that POSITION is not within bold braces. Also, since you need to modify some date attribute in the recordset, I guess its better to select all attributes (*) rather than simply the Employee Number.

Mayank.
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 60 total points
ID: 8178863
Try this:

"SELECT * FROM EMPLOYEE WHERE POSITION = 'CUSTOMER ASSISTANT' ; "

' Please notice the quotes around 'customer assistant', and that POSITION is not within bold braces. Also, since you need to modify some date attribute in the recordset, I guess its better to select all attributes (*) rather than simply the Employee Number.

Mayank.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month12 days, 6 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question