Page 3 of 3 FirstFirst 123
Results 31 to 40 of 40
  1. #31
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I don't use the locals window so I can't say how it works but I wouldn't bank on that being an indicator of everything. That's because I just read an M$ article on it and wonder if "subvariables" is the reason for that.

    OP indicated that table data is being pulled from linked tables or some other type of remote source, so in order to post a db copy, one or more make table queries would be needed to capture a data sample as native tables instead of linked tables. Then the linked tables in the db copy removed, then the native tables renamed to what the linked table names were. That might not be something OP is willing to do.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  2. #32
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Well I can get it to work with a Select query?
    Again, it is using concatenation.

    Code:
    TestQuery Me
    Code:
    Sub TestQuery(frm As Access.Form)
    
    
    Dim db As dao.Database
    Dim qdf As dao.QueryDef
    Dim strSQL As String
    
    
    Set db = CurrentDb()
    
    
    
    
    
    
    strSQL = "SELECT * from TestTransactions WHERE Category LIKE '" & Left(frm.Category, 6) & "*'"
    Set qdf = db.CreateQueryDef("TestQuery", strSQL)
    DoCmd.OpenQuery qdf.Name
    Set db = Nothing
    
    
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #33
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You are not concatenating as instructed in post 14. You are not using delimiters which is why you get popup prompt. Without apostrophe delimiters to define text string Access tries to read Paul as a fieldname and doesn't find one. If your text had space or special characters the code would not even produce a popup but error.
    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.

  4. #34
    pledbetter is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Jan 2010
    Location
    Martinsville, IN
    Posts
    93
    OK here is the solution:

    Code:
    Sub AppendEmployer(frm As Form)Dim strSQLEmp As String
    Dim strSQLAddr As String
    
    
    
    
        strSQLEmpl = "Insert into [tblFormerEmployers] ([numApplID],[txtEmployerName],[txtFmrEmployerPhone],[dteDateFrom],[dteDateTo],[curSalary],[txtSalaryUnit],[txtPosition],[txtLeavingReason]) values(" & numApplicantID & "," & """" & frm.txtFldEmployerName & """" & "," & """" & frm.txtFldFmrEmplPhone & """" & "," & """" & frm.dteFldStartDate & """" & "," & """" & frm.dteFldEndDate & """" & "," & """" & frm.curFldOldSalary & """" & "," & """" & frm.cboPayUnits & """" & "," & """" & frm.txtFldPosition & """" & "," & """" & frm.txtFldReasonForLeaving & """" & ");"
        strSQLAddr = "Insert into [tblAddresses]([txtName], [txtAddress1], [txtAddress2], [txtCity], [txtState], [txtZip], [txtCountry],[txtPostCode]) values(""" & frm.txtFldEmployerName & """" & "," & """" & frm.txtFldAddreess1 & """" & "," & """" & frm.txtFldAddreess2 & """" & "," & """" & frm.txtFldCity & """" & "," & """" & frm.txtFldState & """" & "," & """" & frm.txtFldZipCode & """" & "," & """" & frm.txtFldCountry & """" & "," & """" & frm.txtFldPostalCode & """" & ");"
        
        'Make an entry into the Former Employers and Addresses Tables and clear the form for more input
        
        DoCmd.RunSQL strSQLEmpl
        DoCmd.RunSQL strSQLAddr
        
        With frm
            .txtFldEmployerName = ""
            .txtFldAddreess1 = ""
            .txtFldAddreess2 = ""
            .txtFldCity = ""
            .txtFldState = ""
            .txtFldZipCode = ""
            .txtFldCountry = ""
            .txtFldPostalCode = ""
            .txtFldFmrEmplPhone = ""
            .dteFldStartDate = "1/1/1900"
            .dteFldEndDate = "12/31/1900"
            .curFldOldSalary = 0
            .cboPayUnits = "Hour"
            .txtFldPosition = ""
            .txtFldReasonForLeaving = ""
        
        End With
    
    
    End Sub
    Isn't that the most non-intuitive, confusing, "quotation mark Hell" solution you've ever seen? Note how everything requires FOUR quotation marks to satisfy Microsoft's SQL engine, yet in another stunning example of inconsistency, THREE were required to start of the string for my second append query. Why three? Who cares. This works. Now on to error trapping...

  5. #35
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Well, if you had used single quotes as previously mentioned, it would have been a lot easier.

    Only time that will not work, is if you have a single quotation mark wthin the data, like O'Malley
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #36
    pledbetter is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Jan 2010
    Location
    Martinsville, IN
    Posts
    93
    Can you show me an example?

  7. #37
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Bit hard without the controls, but have a try with
    Code:
    strSQL ="insert into [tblFormerEmployers] ([numApplID],[txtEmployerName],[txtFmrEmployerPhone],[dteDateFrom],[dteDateTo],[curSalary],[txtSalaryUnit],[txtPosition],[txtLeavingReason]) values(" & numApplicantID & ", '" &  txtFldEmployerName & "', '" & txtFldFmrEmplPhone & "', #" & dteFldStartDate & "#, #" &  dteFldEndDate & "#, " &  curFldOldSalary & " , "& cboPayUnits & ",'" txtFldPosition & "', '" & txtFldReasonForLeaving) & "';"
    and debug.print that and correct as needed.
    This also assumes that you are using USA dates, going by your location.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #38
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Alternative is to open recordset and use recordset AddNew method to create record. Then don't need delimiters and apostrophe in data is not an issue. https://learn.microsoft.com/en-us/of...new-method-dao

    When only adding records, open empty recordset: SELECT * FROM table WHERE 0=1
    Last edited by June7; 10-01-2024 at 08:17 AM.
    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.

  9. #39
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Another alternative is to use a QueryDef and parameters, which removes any need for data typing from form values.

    There is very clever coded example here : https://www.access-programmers.co.uk...-query.297170/
    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 ↓↓

  10. #40
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 3 of 3 FirstFirst 123
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 44
    Last Post: 01-04-2021, 02:57 PM
  2. my first DoCmd.RunSQL
    By broecher in forum Programming
    Replies: 4
    Last Post: 11-05-2010, 09:35 PM
  3. docmd.runsql update
    By Mitch_Aus in forum Programming
    Replies: 2
    Last Post: 10-05-2010, 09:45 AM
  4. Problem with DoCmd.RunSQL
    By Peter01 in forum Programming
    Replies: 2
    Last Post: 09-10-2009, 07:11 PM
  5. docmd.runsql not working
    By Rameez in forum Programming
    Replies: 3
    Last Post: 08-07-2009, 10:07 AM

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