Solved

Data type questio :How to use a data type other than a variant

Posted on 2003-10-27
2
153 Views
Last Modified: 2012-05-04
Hi,
In my application, I deal with dates which I pull from a database. For some of the records, the date field is blank in the database. When I pull the dates from the database and assign it to a variable (say x), i assign x the value -1 if the date field is blank. In order to do this I need to declare x as a variant(since it has to store a dae variabl or -1). I do not want to store it as a variant. Please let me know of a better way. I am assigning -1 to do some basic error checking. For eg i might do a simple check like this:
if x <> -1 then
     'Do nothing or report date is empty
else
    'use the date fields
end if

hope i have made myself clear.
thanks.
Yegnaram Iyer
0
Comment
Question by:YegnaramIyer
2 Comments
 
LVL 8

Accepted Solution

by:
fozylet earned 65 total points
ID: 9629672
If checking for an empty string or a date available is the only intention,
i would rather use IsDate(x), rather than complicating things.

If IsDate(x) Then
'use the date
Else
'do nothing
End If

If your requirement is not that simple, and you don't want to use Variant, you can use String or Long
Since you can't store -1 in a string ("-1" you can store), you could go for Long.

myLong = CInt(Year(myDate))*10000 + CInt(Month(myDate))*100 + CInt(Day(myDate))

this will give you myLong = yyyymmdd

Then you may extract the date back from it with a reverse process, or by assigning it to a string and doing string manipulation.
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 60 total points
ID: 9629710
I use 1/1/1900 as an empty date, and translate the blank date to this.  This way you can use a Date data type, instead of a variant.

Dim CurrentDate As Date

If IsNull(DateField) Then
   CurrentDate = CDate("1/1/1900")
Else
   CurrentDate = DateField
EndIf
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now