Results 1 to 4 of 4
  1. #1
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215

    RunSQL syntax help

    I have query that I need to convert to VBA RunSQL syntax

    UPDATE StatusT SET StatusT.Status = [Forms]![Main]![Control1]
    WHERE (((StatusT.ID1)=[Forms]![Main]![Control2] & "." & StrOE(i)));
    The status references a form control, and the ID references a form control too. The ID itself is a combination of a form control and something else, which I define in a string array.

    That is, the ID takes the form of

    A1.Ohio
    A2.Minnesota

    So, I would just define StrOE = Array (Arkansas, Nebraska, ... etc) and just call on it in a for loop

    I have no idea how to write this in the syntax required for a RunSQL command.

    Any help is appreciated.

    Thanks,

    PS -

    This is what I have that's giving me syntax errors

    DoCmd.RunSQL ("UPDATE StatusT SET StatusT.Status = [Forms]![MainNavigation]![NavigationSubform].[Form]![EditMetric].[Form]![EMMetric] WHERE (((StatusT.ID1 = [Forms]![MainNavigation]![NavigationSubform].[Form]![EditMetric].[Form]![EMMetricID]" & "." & StrOE(i) & "));")


  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    Try
    Code:
    DoCmd.RunSQL ("UPDATE StatusT SET StatusT.Status =" &   [Forms]![MainNavigation]![NavigationSubform].[Form]![EditMetric].[Form]![EMMetric]  & " WHERE (((StatusT.ID1 =" &   [Forms]![MainNavigation]![NavigationSubform].[Form]![EditMetric].[Form]![EMMetricID]  & "." & StrOE(i) & "));")

  3. #3
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    DoCmd.RunSQL ("UPDATE StatusT SET StatusT.Status=" & StrSta(i) & " WHERE (((StatusT.ID1)=" & MetricID & "." & StrOE(i) & "));")
    I shortened it so it dosent have to call on the forms. I just set whatever controls I had in the form equal to an array of values, so I can just loop through them.

    This gives me an error:

    Sytax error (missing operator) in query expression '-'

  4. #4
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    I got it to work,

    Notice the new syntax...

    DoCmd.RunSQL ("UPDATE StatusT SET StatusT.Status='" & StrSta(i) & "' WHERE (((StatusT.ID1)='" & MetricID & "." & StrOE(i) & "'));")

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

Similar Threads

  1. DoCmd.RunSQL
    By Access_Blaster in forum Programming
    Replies: 6
    Last Post: 07-23-2013, 09:27 PM
  2. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  3. Syntax Error with DoCmd.RunSQL
    By dandoescode in forum Programming
    Replies: 2
    Last Post: 06-25-2012, 11:06 AM
  4. RunSQL issue
    By SemiAuto40 in forum Programming
    Replies: 3
    Last Post: 10-21-2011, 09:11 AM
  5. my first DoCmd.RunSQL
    By broecher in forum Programming
    Replies: 4
    Last Post: 11-05-2010, 09:35 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