date literal with variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Whasigga
    New Member
    • Oct 2007
    • 11

    #1

    date literal with variable

    Hi

    I'm trying to create a form that a user can type in a year, such as 1998, and then click a button that will find out which day of the week that year started on, and then calculate what date every monday in that year will fall on. Basically to find the beginnings of each week in a given year.

    Where I have a question is when I display (in a text box on the form) the full date for January 1, XXXX.

    I know I can say something like:

    Code:
    Me.FirstDay = #01/01/1998#
    But I want to be able to append the year that the user entered to the year portion of the function above.

    I have seen where I can make SQL statements in VBA by doing something like:

    Code:
    mySQLString = " & code & "
    where code is some string that the user entered.

    When I try this syntax with the date, I get an Expression Expected error.

    Is there any way to do this, or is it not possible to use a variable in the date?

    thanks
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hi, Whasigga.

    Take a look at DateSerial, WeekDay and DateAdd functions.

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      Here's a start for you, where the textbox to enter the desired year is named EnteredYear and the button is named FindFirstOfYear. The results in this example is posted in a message box, but you could, of course, assign it to a textbox or such:

      [CODE=vb]Private Sub FindFirstOfYear _Click()
      Dim NewYearsDay As Date
      NewYearsDay = "01/01/" & EnteredYear
      MsgBox NewYearsDay & " was a " & Format(NewYears Day, "DDDD")
      End Sub
      [/CODE]
      Welcome to TheScripts!

      Linq ;0)>

      Comment

      Working...