Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default 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?)
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default 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?)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default 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)

  #4   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default 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)

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recreating the DateSerial()/Date() function Conan Kelly Excel Worksheet Functions 1 March 1st 08 04:43 AM
DateSerial Troubles rockerx Excel Programming 1 March 14th 07 08:14 PM
Remove Holidays as DateSerial using Case David Excel Programming 3 August 20th 06 02:59 AM
Time/DateSerial Numeric Value Jay Excel Worksheet Functions 4 March 16th 05 03:34 AM


All times are GMT +1. The time now is 03:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"