• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 544
  • Last Modified:

Get Current Date in VB6 Macro

Experts,

I am creating a Macro in Access.  I don't know how to have the Macro enter the current date in a field.  The format that I am looking for would be: 05/04/06.  Please let me know.

Thanks a lot.
0
jjrr007
Asked:
jjrr007
1 Solution
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Have you tried:

=Date()

or

Date()
0
 
rettiseertCommented:
Format(Date(), "mm/dd/yy")
0
 
Robberbaron (robr)Commented:
I know you said your desired format is 05/04/06 but this will often lead to problems with access / vb interpreting the date.
05/04/06 could be 5 April , May 4th etc depending upon where you live.

use format(now(),"mmm/dd/yyyy") to generate an unambiguous date STRING.  VB/Access will then be able to perfectly understand and parse the string into the required date format.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jjrr007Author Commented:
The commands you provided will it insert the date?  

Is the code you provided for setting a parameter or variable... I need it to insert the date.  Please confirm.  Thanks.
0
 
Robberbaron (robr)Commented:

could be either.

variabledate=format(now(),"mmm/dd/yyyy")


'rs=existing recordset
rs.fields("DateField")=variabledate
rs.update

sSQL="UPDATE table SET Datefield = ' " & variabledate & "'"
cn.Execute sSQL


Need your partial script to help further...
0
 
jjrr007Author Commented:
Thanks.  I will provide partial code when I get back on Monday.  
0
 
jjrr007Author Commented:
I am really sorry about the delay.  
Again, I need the macro (written in Vb6) to input the current date.  The current syntax is like:

        .TransmitANSI "05"
        .TransmitTerminalKey rcIBMRightKey
        .TransmitANSI "13"
        .TransmitTerminalKey rcIBMTabKey
        .TransmitANSI "05"
0
 
jjrr007Author Commented:
I may have to use another sub routine- I am not sure.

 But the existing code for how the date is inputed is above.  Please assist as soon as possible.  Thanks again.
0
 
Robberbaron (robr)Commented:
OK... this is different. I think we have been assuming you want to enter the current date in a DATABASE field.  

But you want to enter it into a FORM field, in fact into 3 different fields !

Do you have to have different fields ?  

I assume they are textbox fields ?

But the form fields generally have names. A good suggestiion for field names would be
 txtDay, txtMonth , txtYear

so then in code you can say.
txtDay.Value="23"
txtMonth.Value="05"
TxtYear.Value="06"

or to use current date  
txtDay.Value=Format(Now(), "dd")
txtMonth.Value=Format(Now(), "mm")
txtYEar.Value=Format(Now(), "yy")
0
 
Robberbaron (robr)Commented:
I've cofused the issue a little.....
DATABASE has fields
FORMS have controls.  

Do you have to have different controls ?  

I assume they are textbox controls ?

But the form controls generally have names. A good suggestiion for control names would be
 txtDay, txtMonth , txtYear
0
 
jjrr007Author Commented:
This is actually a macro written for a telnet session- sorry for the confusion(I don't know a lot about this).  So this Macro will type in the month day and year into the screen.  There is no fields it just types in the values.  So it should use the existing format of:
 
        .TransmitANSI "05"
        .TransmitTerminalKey rcIBMRightKey
        .TransmitANSI "13"
        .TransmitTerminalKey rcIBMTabKey
        .TransmitANSI "05"



So for the above example it will type in the date 05/13/05.  The slashes are prefilled.  I don't know how to instruct the  Macro to transmit the current month day year.  I would have to use the existing format.  So maybe something like this for month:
        .TransmitANSI txtMonth.Value=Format(Now(), "mm")

Please advise.  Thanks.
   
0
 
Robberbaron (robr)Commented:
Definitely needed to know that info !

You almost had it correct... you dont have a VBA form so no use for txtMonth etc

        .TransmitANSI Format(now(),"mm" )         ' month index 05=May
        .TransmitTerminalKey rcIBMRightKey
        .TransmitANSI Format(now(),"dd" )           'day of month ie "13"
        .TransmitTerminalKey rcIBMTabKey
        .TransmitANSI Format(now(),"yy" )           'year   ie  "05"

0
 
jjrr007Author Commented:
Thank you so much.  I will try this as soon as I get back in the office- early this week.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now