ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   using dateserial in vb (https://www.excelbanter.com/excel-programming/391267-using-dateserial-vbulletin.html)

mwam423

using dateserial in vb
 
am trying to convert date info into it's serial date value with following
code (month and year provided by user):

acctmon = Application.InputBox("Please enter month value between 1 and 12",
"Enter month", Month(Now), , , , , 1)

acctyr = Application.InputBox("Please enter year", "Enter year", Year(Now),
, , , , 1)

Dim date As Integer
date = Application.DateSerial(acctyr, acctmon, 1)

however, get the error message: run-time error '438': object doesn't support
this property or method

what does this mean, and what do i have to do to return a serial value? (is
there another function i can use to accomplish this?)

JMB

using dateserial in vb
 
First, I wouldn't use date for a variable name since it is a vba keyword.
Second, if you declare it as an integer, you can't use dates after 9/16/89
w/o getting an overflow error. Third, leave out application when you call
dateserial.

Try:

Dim lngDate as long
lngDate = DateSerial(acctyr, acctmon, 1)


"mwam423" wrote:

am trying to convert date info into it's serial date value with following
code (month and year provided by user):

acctmon = Application.InputBox("Please enter month value between 1 and 12",
"Enter month", Month(Now), , , , , 1)

acctyr = Application.InputBox("Please enter year", "Enter year", Year(Now),
, , , , 1)

Dim date As Integer
date = Application.DateSerial(acctyr, acctmon, 1)

however, get the error message: run-time error '438': object doesn't support
this property or method

what does this mean, and what do i have to do to return a serial value? (is
there another function i can use to accomplish this?)


mwam423

using dateserial in vb
 
dear JMB, thanks answering and also for the quick response, definitely works
now. did have question, could i have used functions like DATEVALUE or DATE
to obtain serial value, and if so, what would the code look like? (just want
the simple, basic stuff, thank you)

"JMB" wrote:

First, I wouldn't use date for a variable name since it is a vba keyword.
Second, if you declare it as an integer, you can't use dates after 9/16/89
w/o getting an overflow error. Third, leave out application when you call
dateserial.

Try:

Dim lngDate as long
lngDate = DateSerial(acctyr, acctmon, 1)


JMB

using dateserial in vb
 
datevalue is for converting string representations of dates to serial date
values

MyDate = DateValue("February 12, 1969")
MyDate = DateValue("2/12/1969")

but from VBA help:
If date is a string that includes only numbers separated by valid date
separators, DateValue recognizes the order for month, day, and year according
to the Short Date format you specified for your system.

which could cause you a problem if the code is intended to run on different
machines as their settings could vary.

The Date function, in VBA, returns the current system date - it is not the
same as the XL worksheet function Date.

Since your data obtained from the user is numeric, I'd stick w/Dateserial.


"mwam423" wrote:

dear JMB, thanks answering and also for the quick response, definitely works
now. did have question, could i have used functions like DATEVALUE or DATE
to obtain serial value, and if so, what would the code look like? (just want
the simple, basic stuff, thank you)

"JMB" wrote:

First, I wouldn't use date for a variable name since it is a vba keyword.
Second, if you declare it as an integer, you can't use dates after 9/16/89
w/o getting an overflow error. Third, leave out application when you call
dateserial.

Try:

Dim lngDate as long
lngDate = DateSerial(acctyr, acctmon, 1)



All times are GMT +1. The time now is 02:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com