Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 19th, 2005, 07:06 AM
thayalan44 thayalan44 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 29 thayalan44 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 10 m 55 sec
Reputation Power: 0
Convert string to date using vb with access as database

I want to convert a string variable called, strfl to a date using vb. I am using the codes shown below. The database is msaccess. The following code throws an error when the code, 'rstDelete.MoveFirst' is executed.
Error message : "Either BOF or EOF is true........".
But there is a value for hdate in the table called holiday which is equal to "20-09-05".
So, the problem has to be with conversion of string to date which is in the part of the code, "hdate = #" & (strfl) & "#"
Can anyone please help me by showing the proper string to date conversion that works with ms access?

Code:
strfl = "20-09-05" 
If strfl <> "" Then
    rstDelete.Open "Select * from holiday where hdate = #"   & (strfl) & "#", db, adOpenKeyset, adLockOptimistic
   rstDelete.MoveFirst
   While Not rstDelete.EOF
      rstDelete.Delete
   Wend
   rstDelete.Close

Reply With Quote
  #2  
Old September 19th, 2005, 02:24 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 29 m 58 sec
Reputation Power: 181
Make sure your date string is in the same locale as your access db, i.e., mm/dd/yyyy. Next, try using / instead of - as a seperator, and use a 4 digit year. The acceptable date string formats for Access are shown in the Access online help, take a look there and make sure you're using a valid date string.

The error message indicates your query doesn't return any records, try it in access itself and verity that the query string works.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #3  
Old September 20th, 2005, 04:06 AM
thayalan44 thayalan44 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 29 thayalan44 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 10 m 55 sec
Reputation Power: 0
Thank you Doug. I have put the year in the 4 digit format and it works. In the code, I am assuming everything to be from the year 2000 onwards. I am using vb 6.0 and ms access installed from Office XP 2003.

Code:
   str = Mid(strfl, 1, 6)
   substr = Mid(strfl, 7, 2)
   rstDelete.Open "Select * from holiday where hdate =#" & str & "20" & substr & "#", db, adOpenKeyset, adLockOptimistic
   rstDelete.MoveFirst
   While Not (rstDelete.EOF Or rstDelete.BOF)
      rstDelete.Delete
      rstDelete.MoveNext
   Wend
   rstDelete.Close

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Convert string to date using vb with access as database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT