|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Convert string to date using vb with access as database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|