Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 149
  • Last Modified:

simple query and automatic date

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
willgilmore
Asked:
willgilmore
  • 4
  • 3
  • 2
  • +2
1 Solution
 
sazhagianambiCommented:
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
 
DocMCommented:
Hy,

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

strDate = Format(Date, "dd/mm/yyyy")
 
0
 
hazgodCommented:
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
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!

 
Mayank SAssociate Director - Product EngineeringCommented:
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
 
hazgodCommented:
date$ is the system date function
0
 
willgilmoreAuthor Commented:
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
 
hazgodCommented:
try doing

dim thisEmployeePos

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

thisEmployeePos= txtEmployeePosition

where does the date come in?
0
 
willgilmoreAuthor Commented:
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
 
hazgodCommented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now