ms access - insert datetime sql syntax? -
i have button executes vba code lists files , date-created. i'm stumped on sql insert datetime format insertion. error returns code 128 upon db.execute. ideas?
do while len(strfile) > 0 'debug.print strfolder & strfile ssql = "insert tblvideos ( filename , filedate) values ('" & strfile & "'," & format(strtodate(datecreated(strfolder & strfile)), "\#yyyy-mm-dd hh:nn:ss\#") & ")" debug.print ssql db.execute ssql, dbfailonerror strfile = dir() loop end sub public function strtodate(strin string) variant dim var variant dim yr variant if len(strin & "") 'strtodate = cdate(mid$(strin, 3, 4) & "/" & left$(strin, 2) & "/" & right$(strin, 4)) var = split(strin, "/") yr = split(var(2), " ") strtodate = var(0) & "/" & var(1) & "/" & yr(0) & " " & yr(1) else strtodate = null end if end function
you error 128 @ line:
db.execute ssql, dbfailonerror
if insert
statement faulty, error db engine. however, error 128, "application-defined or object-defined error", error access' vba host, not db engine. makes me suspect problem not insert
statement (ssql
), rather else in line.
you didn't show how declare db
, give value. in order execute
work, db
must valid dao.database
object reference.
if yours set correctly, should show full path db file ...
debug.print db.name
if gives error, or other db file path, examine how set db
. set current database ...
dim db dao.database set db = currentdb
show how you're setting db
if need that.
Comments
Post a Comment