Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100
    Thank you for your patience. I understand the concept of delimiters, having been a C programmer. I know that if you get the delimiters "unbalanced" you ill have problems. What I don't understand is why the following works and the query with delimters has problems?

    This works:

    SqlQry = "INSERT INTO DowntimeEventNew ([Begin Date], [Begin Time], [End Date], [End Time], [Description], Planned, ReportedBy, EnteredBy, ServerName, UsePhysicalServer, Services)" _
    & "VALUES (CDate([txtBeginDate]), CDate([txtBeginTime]), CDate([txtEndDate]), CDate([txtEndTime]), [txtDescription], [cboPlanned], [txtReportedBy], [txtEnteredBy], [cboServerNm], [cboUsePhysicalServer], [txtServices]);"

    DoCmd.RunSQL SqlQry

    I do get the following error, although it does save the record correctly: Microsoft Access set 1 field(s) to Null due to a type conversion failure, ...

  2. #17
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    When you use Docmd you are invoking the access interpreter, and it understands and recognises all the form control references, and makes allowances for the datatypes as a result.

    When you use CurrentDb.Execute you are bypassing the Access interpreter and passing the SQL as a True SQL query to the database (Jet?) engine.
    It has no idea what the form controls or data types are so you have to explicitly make sure they are passed correctly.

    The second method will almost certainly run quicker and is more portable, but there is some pain involved in creating the query.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #18
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    May I offer a suggestion.

    Define the parameters in your SQL string (or query)

    for every field that references something on a form [FIELDNAME] as an example

    for instance if you were trying to append the field contents from [FIELDNAME] on your form [MYFORM]

    you would have a sql statement like:

    Code:
    PARAMETERS [Forms]![MYFORM]![FieldName] DateTime;
    INSERT INTO tblDocumentSigner ( DS_Date )
    SELECT [Forms]![MYFORM]![fieldname] AS Expr1;
    Sometimes Access can't interpret whether a text box is meant to be a date, a number, text and will throw that parameter error, if you define the field in your parameters it should work fine.

  4. #19
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100
    Micron:

    Thanks for your suggestions. U R right, it was more educational to work it out by myself. I just needed to be pointed in the right direction. I finally got it worked out after many, many false starts. But I now do not get any dat mis-match errors. Thanks, again.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. CurrentDb.Execute INSERT syntax error 3134
    By GraeagleBill in forum Programming
    Replies: 8
    Last Post: 12-19-2015, 09:45 PM
  2. RunSQL vs. QueryDef.Execute vs. CurrentDB.Execute
    By caubetiep1337 in forum Queries
    Replies: 8
    Last Post: 12-16-2015, 05:35 PM
  3. Error in CurrentDb.Execute
    By Stefan Moser in forum Access
    Replies: 5
    Last Post: 04-17-2015, 01:38 PM
  4. vba code help - Currentdb.execute
    By joycesolomon in forum Programming
    Replies: 5
    Last Post: 08-11-2014, 11:25 AM
  5. Replies: 12
    Last Post: 01-24-2014, 02:18 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