Results 1 to 18 of 18

Thread: IsDate Format Date

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Kuala Lumpur
    Posts
    212

    Unhappy IsDate Format Date

    I need some help here. It is about format date on IsDate Function. It seems, that i can't get it right. I hope you can assist me on this. This is what i am trying to achieve. User Input a date in MskEffective Date and automatically Isdate function generate an Expiry Date in MskExpiry. My Problem is each time i enter an effective date it prompt me an Error stated Invalid Property Value on <<FormName.mskExpiry = YearDate - 1>>. Below are my coding. I believe it is my coding problem. I have solved a couple of Error on Date but not this time. I am appreciate with anyone help. Thank you in advance.

    VB Code:
    1. Public Sub Validate(FormName As Form)
    2.  
    3. IntervalY = "yyyy"
    4. If IsDate(FormName.mskEffective) = False Then
    5. MsgBox "Date Wrong Format.Please check Date", vbCritical, "Date Format Incorrect"
    6. FormName.mskEffective.SetFocus
    7. Exit Sub
    8. End If
    9. FirstDate = FormName.mskEffective
    10.      'FirstDate = Format(FirstDate, "dd-mm-yyyy")
    11. number = 1
    12. YearDate = DateAdd(IntervalY, number, FirstDate)
    13.      'YearDate = Format(FirstDate, "dd-mm-yyyy")
    14.      'FormName.mskExpiry = Format(FormName.mskExpiry, "dd-mm-yyyy")
    15. FormName.mskExpiry = YearDate - 1 'ExpiryDate Must Minus One Day
    16. End Sub
    As you can see there are couple of Remarks which i tested out but all fail.
    kC

  2. #2
    Fanatic Member dongaman's Avatar
    Join Date
    Aug 2001
    Location
    xi'an
    Posts
    616
    DO NOT USE IsDate Function,it is very "bad"
    I am just aman.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Kuala Lumpur
    Posts
    212
    What else can i use?
    kC

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by dongaman
    DO NOT USE IsDate Function,it is very "bad"
    why?
    -= a peet post =-

  5. #5
    Fanatic Member dongaman's Avatar
    Join Date
    Aug 2001
    Location
    xi'an
    Posts
    616
    You may need force user input valid date,I means use some combobboxes instead of just a textbox.
    I also met this problem before,i resolved it by this.
    Good luck
    I am just aman.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Kuala Lumpur
    Posts
    212
    Well, my question is about Format Date with IsDate function.
    kC

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Kuala Lumpur
    Posts
    212
    i dont get u, dongaman.
    kC

  8. #8
    Fanatic Member dongaman's Avatar
    Join Date
    Aug 2001
    Location
    xi'an
    Posts
    616
    To peet.
    Such as:
    IsDate("01-22-02")=true 'in yy-mm-dd "01-22-02" is not valid
    I am just aman.

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    No! Please continue to use the IsDate function.
    Besides as I understand your question the error is raised on this line:
    VB Code:
    1. FormName.mskExpiry = YearDate - 1
    You might want to try changing the line with DateAdd instead to substract one day.
    VB Code:
    1. YearDate = DateAdd("d", -1, DateAdd(IntervalY, number, FirstDate))
    Best regards

  10. #10
    Fanatic Member dongaman's Avatar
    Join Date
    Aug 2001
    Location
    xi'an
    Posts
    616
    To Joacim Andersson.
    Do you want IsDate(01-22-33)=true
    I am just aman.

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by dongaman
    To Joacim Andersson.
    Do you want IsDate(01-22-33)=true
    As I understand it kokzai using the format dd-mm-yyyy in his masked edit controls so this wouldn't be an issue.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Kuala Lumpur
    Posts
    212

    Opss...

    VB Code:
    1. FormName.mskEffective = DateAdd("d", -1, DateAdd(IntervalY, number, FirstDate))

    it still hit the same Error.

    Joacim Andersson, it is not the - 1 gave me the Error. Previously, it work fine until i changed my System Date. I do not which to rely on the System Date too much. I rather my application to accpet any format changes on system.Basically, it is the Format Date caused the Error.

    I have solved a couple of Same Error with Format Date but this time i Fail
    kC

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    I can't see the declaration of YearDate in your code. What kind of data type does it have?

  14. #14
    Registered User
    Join Date
    Oct 2001
    Location
    mysore
    Posts
    60

    isdate answer

    i saw your coding i think u have made mistake in isdate function
    first parametr is string so u have to "d" or "m"or "yyyy"in first parameter.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Kuala Lumpur
    Posts
    212
    This is what i have

    VB Code:
    1. Global FirstDate As Date
    kC

  16. #16
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    OK! A Date always contains both a date and time value so you can't assign that to your masked edit control since it's not the correct format.
    VB Code:
    1. FormName.mskExpiry.Text = Format$(YearDate - 1, "dd-mm-yyyy")
    Best regards

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Kuala Lumpur
    Posts
    212
    Well, Thanks Joacim Andersson. It works with no Error. But the output is not accurate.

    It should be + 1 Year and Then - (minus) One Day = mskExpiry.
    kC

  18. #18
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Try this
    VB Code:
    1. Public Sub Validate(FormName As Form)
    2.     IntervalY = "yyyy"
    3.     If IsDate(FormName.mskEffective) = False Then
    4.         MsgBox "Date Wrong Format.Please check Date", vbCritical, "Date Format Incorrect"
    5.         FormName.mskEffective.SetFocus
    6.         Exit Sub
    7.     End If
    8.     FirstDate = FormName.mskEffective
    9.     number = 1
    10.     YearDate = DateAdd("d", -1, DateAdd(IntervalY, number, FirstDate))
    11.     FormName.mskExpiry.Text = Format$(YearDate, "dd-mm-yyyy")
    12. End Sub
    Best regards

Posting Permissions

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



Click Here to Expand Forum to Full Width