willgilmore
asked on
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.
"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.
Hy,
strQuery= "Select [EmployeeNumber] from EMPLOYEE where [Position] = Customer Assistant"
strDate = Format(Date, "dd/mm/yyyy")
strQuery= "Select [EmployeeNumber] from EMPLOYEE where [Position] = Customer Assistant"
strDate = Format(Date, "dd/mm/yyyy")
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$
so you want to do:
dim thisDeparture as string
thisDeparture = (Select [EmployeeNumber] from EMPLOYEE where [Position] = Customer Assistant) & " " & date$
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.
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.
date$ is the system date function
ASKER
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
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
try doing
dim thisEmployeePos
Select [EmployeeNumber] from EMPLOYEE where [Position] = Customer Assistant)
thisEmployeePos= txtEmployeePosition
where does the date come in?
dim thisEmployeePos
Select [EmployeeNumber] from EMPLOYEE where [Position] = Customer Assistant)
thisEmployeePos= txtEmployeePosition
where does the date come in?
ASKER
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.
if the employee position is a number then you will need to do
thisEmployeePos= val(txtEmployeePosition)
to get the number from the text box
thisEmployeePos= val(txtEmployeePosition)
to get the number from the text box
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.
"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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
dim dat as date
dat=Format(Date(),"dd/mm/y
After,
Select [EmployeeNumber] from EMPLOYEE where [Position] = Customer Assistant and Date=dat
This Will return the Result For Current Date.
Nambi