HELP!!! Object Variable or Block Variable Not Set

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

Hi,

I'm new on Access XP. I'm able to import the text file in the table. I'm
trying to convert the text file (date) to Access Table (date). In the
table, I set "Date/Time" but it won't allow me and the message said "Data
Type Conversion Type". I change to "Text" and it works. I don't like the
text file (Date). It look like "19980223" but I want to change to
"DD/MM/YYYY".

Is there a way to set this code (below) that set a default to "DD/MM/YYYY"?
Same problem with "Number".

rs![DATE] = Mid(StrNAME, 166, 8)

Your help would be much appreciated.
Thanks
 
Try using the DateSerial function to change the string of numbers into a
date. You can format it later, for now, just get a date value into the
field. Also, Date isn't a good name for a field, it is a reserved word and
has the potential to cause you problems.

strTempDate = Mid(StrNAME, 166, 8)
rs![DATE] = DateSerial(Left(strTempDate, 4), Mid(strTempDate, 5, 2),
Right(strTempDate, 2))
 
Wayne is correct, Bill. What may also be useful to know is that dates in Jet
are not carried as text. They are stored as IEEE 64-bit (8-byte)
floating-point numbers that represent dates ranging from 1 January 100 to 31
December 9999 and times from 0:00:00 to 23:59:59. Access deals with
converting them to something we humans can understand. For displaying dates,
you need to read up on the Format function.

Wayne Morgan said:
Try using the DateSerial function to change the string of numbers into a
date. You can format it later, for now, just get a date value into the
field. Also, Date isn't a good name for a field, it is a reserved word and
has the potential to cause you problems.

strTempDate = Mid(StrNAME, 166, 8)
rs![DATE] = DateSerial(Left(strTempDate, 4), Mid(strTempDate, 5, 2),
Right(strTempDate, 2))

--
Wayne Morgan
MS Access MVP


Bill said:
Hi,

I'm new on Access XP. I'm able to import the text file in the table.
I'm trying to convert the text file (date) to Access Table (date). In
the table, I set "Date/Time" but it won't allow me and the message said
"Data Type Conversion Type". I change to "Text" and it works. I don't
like the text file (Date). It look like "19980223" but I want to change
to "DD/MM/YYYY".

Is there a way to set this code (below) that set a default to
"DD/MM/YYYY"? Same problem with "Number".

rs![DATE] = Mid(StrNAME, 166, 8)

Your help would be much appreciated.
Thanks
 
In your text date, is the year always 4 characters, month 2 characters and
day 2 characters? If Yes, try this:
Add a new field named ConvertedDate to your table and set the data type as
Date/Time. Create an update query based on your table and include your Date
field and the ConvertedDate field. Assuming your text date field is named
MyDate, put the following expression in the Update To line under
ConvertedDate:
DateSerial(Val(Left([MyDate],4)),Val(Mid([MyDate],5,2)),Val(Right([MyDate],2)))

When you run this query, ConvertedDate should now be your dates in Date/Time
format.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Stumped By Dates 4
Syntax Error 4
Date problem 5
convert date 1
Convert Text to Date 3
Not returning a value 7
Forcing a date entry format of dd/mm/yyyy 1
date calculations - please help 2

Back
Top