Results 1 to 3 of 3
  1. #1
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254

    CurrentDB.Execute Insert Into with date variable

    Evidently, I'm having one of those moments. Any help would be appreciated.



    Code:
    dim dbs as Database
    Set dbs = CurrentDB
    dim x1 as Date
    x1 = Now()
    dim w1 as long
    w1 = Me![cboEntity].Value
    dim mySString as String
    mySString ="INSERT INTO tblSession (fkUserID, fkEntityID, sessiondteStart) VALUES (Me![txtUID4S], w1,x1)"
    CurrentDB.Execute mySString, dbFailOnError
    Code is throwing error 3061 parameter and I had some syntax errors as well in the vbeditor.

    with the x1 variable I have tried several versions with combinations of '"# " & x1 & "#"', but can't seem to get it to work.

    Thanks, for any help.

    Jim

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Concatenate variables.

    "INSERT INTO tblSession (fkUserID, fkEntityID, sessiondteStart) VALUES (" & Me![txtUID4S] & ", " & w1 & ", #" & x1 & "#)"

    Note the # delimiters for date field parameters. Text field would need apostrophe delimiters.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254
    June7 - Thanks so much for your help. I'll mark this as solved. Jim

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-30-2015, 10:06 AM
  2. vba code help - Currentdb.execute
    By joycesolomon in forum Programming
    Replies: 5
    Last Post: 08-11-2014, 11:25 AM
  3. Replies: 12
    Last Post: 01-24-2014, 02:18 PM
  4. Update sql using currentdb.execute
    By laavista in forum Access
    Replies: 13
    Last Post: 08-15-2011, 03:51 PM
  5. Replies: 3
    Last Post: 02-16-2010, 10:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums