vb6 error 380 Datepicker, bust just in certain dates

Im having a problem with a datepicker on vb6, but this jus happen on certain dates, for example 31/01/2017, but with another dates it works fine.

error image

I appreciate the help

Upvotes: 1

Views: 255

Answers (1)

jac
jac

Reputation: 9726

This almost certainly has to do with how you are setting the date in the control.

For instance if the control's value is ANY month that does not have 31 days then you will get that error. Trying to set the control to 31/02/2017 would cause an error 380.

There are two approaches you can take to fix this.

  1. Reverse the order you set the date components.

    dtFecha.Year = Year(fcsAux.Fields("xf3ch4"))
    dtFecha.Month = Month(fcsAux.Fields("xf3ch4"))
    dtFecha.Day = Day(fcsAux.Fields("xf3ch4"))
    
  2. Set the Value property instead of the date components. dtFecha.Value = "31/02/2017"

    dtFecha.Value = rcsAux.Fields("xf3ch4").Value
    

The first approach ensures the month is always appropriate for the day. The second approach sets the entire value at one shot and should be a valid date.

Upvotes: 3

Related Questions