Solved

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

Posted on 2003-10-27
2
156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month8 days, 4 hours left to enroll

617 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