+ Reply to Thread
Results 1 to 2 of 2

Userform - Date entry

  1. #1
    Registered User
    Join Date
    10-25-2012
    Location
    Aberdeen
    MS-Off Ver
    Excel 2010
    Posts
    2

    Userform - Date entry

    Hello All,

    I am currently trying to write a simple visual basic application (my first time using the language) which calls a userform with several textboxes. The information from these textboxes will eventually be used to generate a report. I am having some problems entering a date into one of these textboxes. What I would like to do is add a calculated number of days to this date and output a new date using DateAdd(). However I am getting a runtime error 13 type mismatch. I think this is because the date string is incorrectly formatted as my code works with NOW() replacing DischargeDate.

    Here is my code

    Please Login or Register  to view this content.
    Please excuse any vulgarities in this code as it is my first time using VBA and I am unsure how to construct an application 'correctly'. I think the problem is that I enter a string corresponding to the date of discharge in the format dd/mm/yyyy into a text box. I then call DateDischarge = Me.tb_DateDischarge.Value which passes a string to the variable DischargeDate which i have defined Dim DischargeDate as Date. I then try to use the function DateAdd("d", ChildRestriction, DischargeDate) where ChildRestriction is an integer. I get a runtime error at this point I think because DischargeDate remains a string and not a date as required

    How can I get around this issue?

  2. #2
    Registered User
    Join Date
    10-25-2012
    Location
    Aberdeen
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Userform - Date entry

    I have managed to solve this problem but I do not think I understand the reason why

    I have changed the block
    Please Login or Register  to view this content.
    which doesn't work to

    Please Login or Register  to view this content.
    To me both code blocks are equivalent. Why does one work and the other does not

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1