Results 1 to 3 of 3
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question SQL + VBA String

    I'm trying to run the below SQL string in VBA. However, when I do I receive a data type mismatch error. I have also tried using #" & dtPayrollMonth & "# for the date variable, but received the same error. I also tried surrounding "Corp" in "", but that didn't work. Thanks in advance.

    Code:
        mySQL = "INSERT INTO tblPayroll_Data ( PayrollAmt, Trailing12Payroll, Department, PayrollMonth ) " & _
            "SELECT Sum(tblPayroll_Import.[" & arrFields(i) & "]) AS [SumOf" & arrFields(i) & "], Sum(tblPayroll_Import.[Trailing 12 Mos#]) " & _
            "AS [SumOfTrailing 12 Mos#], 'Corp' AS Department, Cdate(" & dtPayrollMonth & ") AS PayrollMonth " & _
            "FROM tblPayroll_Import;"
    db.Execute mySQL, dbFailOnError


  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,538
    When the code breaks, have you checked that dtPayrollMonth is holding a value that can be converted to a date.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Unfortunately the error lied in the table I was importing. I made a stupid assumption that a numeric field was actually formatted as numeric...It was formatted as text. Problem resolved. Thanks for the feedback/input.

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

Similar Threads

  1. VBA string with OR expression
    By hmcquade in forum Forms
    Replies: 3
    Last Post: 06-24-2011, 07:59 AM
  2. Connection String
    By cradaa in forum Access
    Replies: 4
    Last Post: 05-24-2011, 07:28 AM
  3. Format within a string
    By wdrspens in forum Reports
    Replies: 1
    Last Post: 04-16-2011, 05:51 PM
  4. Setting SQL = string
    By jasonbarnes in forum Programming
    Replies: 7
    Last Post: 02-18-2011, 11:02 AM
  5. Formating string
    By Alex Motilal in forum Reports
    Replies: 7
    Last Post: 12-10-2010, 06:09 AM

Tags for this Thread

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