Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-10-27
2
Medium Priority
?
159 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 195 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 180 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

824 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