Results 1 to 5 of 5
  1. #1
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108

    Help~ Ado Vba - trying to call strsql(INSERT)

    I need help with ado connection !

    I'm trying to do is to do a concatenate of my 2 fields( ([PROD_SAP.PAT_LASTNAME] & [PROD_SAP.PAT_FIRSTNAME]) from my PROD_SAP table.
    Then, the result will be pasted in the same table but column("PATNAME")


    I'm stuck with this part .. how to call my strsql?
    Any idea on how to do this part?
    Thanks in advance


    Code:
       objRecordset.Fields.Item(4).Value =
                 ' Item(4) = PATNAME column . I wanna paste here the concatenate value
    

    Code:
    Sub Update_ConcateProdSAP()
    Dim objRecordset As ADODB.Recordset
    Set objRecordset = New ADODB.Recordset
    Dim i As Integer
    'Dim value As Variant
    Dim strConcateSQL As String
    
    strConcateSQL = " INSERT INTO PROD_SAP ( ID , EXT_PAT_ID , PAT_LASTNAME " & _
                    " PAT_FIRSTNAME , PATNAME , GENDER , DOB , CREATE_DATE , " & _
                    " LAST_UPDATE_DATE , C_SOURCE , CAT_TYPE ) " & _
                    " SELECT ( PROD_SAP.ID , PROD_SAP.EXT_PAT_ID , PROD_SAP.PAT_LASTNAME " & _
                    " PROD_SAP.PAT_FIRSTNAME , ([PROD_SAP.PAT_LASTNAME] & [PROD_SAP.PAT_FIRSTNAME]) AS PATNAME , " & _
                    " PROD_SAP.GENDER , PROD_SAP.DOB , PROD_SAP.CREATE_DATE , " & _
                    " PROD_SAP.LAST_UPDATE_DATE , PROD_SAP.C_SOURCE , PROD_SAP.CAT_TYPE "
    'initated recordset object
    objRecordset.ActiveConnection = CurrentProject.Connection
     Call objRecordset.Open("Prod_SAP", , , adLockBatchOptimistic)
      
     Do Until objRecordset.EOF
         'check for match
         
        If objRecordset.Fields.Item(2).value Is Not Null Then
        ' Item(2) = [PROD_SAP.PAT_LASTNAME] 
        'call strConcateSQL function/method/sql
        objRecordset.Fields.Item(4).Value =
        objRecordset.UpdateBatch
        
        Else
        
        objRecordset.MoveNext
    Loop
            
        objRecordset.Close
        Set objRecordset = Nothing
        
    End Sub


  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I am not an expert with ADO and I am not familiar with the nuances of UpdateBatch. However, I do not believe there is a way to avoid designating a cursor location when updating records. In other words, you cannot use an INSERT INTO statement.

    What happens if you hardcode some text as a test? Create a copy and test your code on a COPY.

    objRecordset.Fields.Item(4).Value = "Foo Bar"

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    1) This would be easier in DAO
    2) You shouldn't be storing the concatenation - it can be derived in a query.
    3) There is a syntax error: the sub query in the append query strConcateSQL is not correctly formed. The "FROM" clause is missing.
    You have:
    Code:
        strConcateSQL = " INSERT INTO PROD_SAP ( ID , EXT_PAT_ID , PAT_LASTNAME " & _
                        " PAT_FIRSTNAME , PATNAME , GENDER , DOB , CREATE_DATE , " & _
                        " LAST_UPDATE_DATE , C_SOURCE , CAT_TYPE ) " & _
                        " SELECT ( PROD_SAP.ID , PROD_SAP.EXT_PAT_ID , PROD_SAP.PAT_LASTNAME " & _
                        " PROD_SAP.PAT_FIRSTNAME , ([PROD_SAP.PAT_LASTNAME] & [PROD_SAP.PAT_FIRSTNAME]) AS PATNAME , " & _
                        " PROD_SAP.GENDER , PROD_SAP.DOB , PROD_SAP.CREATE_DATE , " & _
                        " PROD_SAP.LAST_UPDATE_DATE , PROD_SAP.C_SOURCE , PROD_SAP.CAT_TYPE "
    Need to say which table(s) the records are being selected from ......

  4. #4
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by ssanfu View Post
    1) This would be easier in DAO
    2) You shouldn't be storing the concatenation - it can be derived in a query.
    3) There is a syntax error: the sub query in the append query strConcateSQL is not correctly formed. The "FROM" clause is missing.
    You have:
    Code:
        strConcateSQL = " INSERT INTO PROD_SAP ( ID , EXT_PAT_ID , PAT_LASTNAME " & _
                        " PAT_FIRSTNAME , PATNAME , GENDER , DOB , CREATE_DATE , " & _
                        " LAST_UPDATE_DATE , C_SOURCE , CAT_TYPE ) " & _
                        " SELECT ( PROD_SAP.ID , PROD_SAP.EXT_PAT_ID , PROD_SAP.PAT_LASTNAME " & _
                        " PROD_SAP.PAT_FIRSTNAME , ([PROD_SAP.PAT_LASTNAME] & [PROD_SAP.PAT_FIRSTNAME]) AS PATNAME , " & _
                        " PROD_SAP.GENDER , PROD_SAP.DOB , PROD_SAP.CREATE_DATE , " & _
                        " PROD_SAP.LAST_UPDATE_DATE , PROD_SAP.C_SOURCE , PROD_SAP.CAT_TYPE "
    Need to say which table(s) the records are being selected from ......
    I can only achieve this by a query uh ?

    Thanks for pointing out my errors .

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I can only achieve this by a query uh ?
    No, I didn't say that.
    If you fix the syntax, your code (if it ran) would update all records because there is no criteria to limit what records would be selected for the append.


    But the code starts out by having a bulk append, then switches to code to loop through a record set to concatenate two fields.
    Maybe you could explain more about what you are trying to do???

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

Similar Threads

  1. How to add counter to StrSQL vba?
    By Jo.. in forum Queries
    Replies: 2
    Last Post: 09-09-2015, 08:09 AM
  2. Replies: 3
    Last Post: 01-27-2015, 12:25 PM
  3. VBA strSQL mismatch
    By SPW_12 in forum Programming
    Replies: 12
    Last Post: 07-31-2012, 07:47 PM
  4. Need to add 2nd criteria to strSQL
    By robsworld78 in forum Forms
    Replies: 8
    Last Post: 08-23-2011, 02:57 PM
  5. DLookup in strSQL for OpenRecordset
    By szucker1 in forum Programming
    Replies: 2
    Last Post: 07-30-2011, 06:00 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