Results 1 to 7 of 7
  1. #1
    Edward_ is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    38

    Updating an ADODB record syntax, I'm very close, but missing something. VB6

    I have no errors with this simple code, but it doesn't write the updated field values to the table.


    What am I overlooking? I'm moving everything in this project from DAO to ADO, this is my first save edited record procedure.
    Code:
    Dim iSQLStr As String
    Dim rsCon As ADODB.Recordset
    Set cnCon = New ADODB.Connection
    Set rsCon = New ADODB.Recordset
    cnCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                             "Data Source=" & GetDataPath
    cnCon.Open
      iSQLStr = "SELECT * FROM tblData WHERE patID = '" & cmbID.Text & "' & AND Num = '" & cmbpatNum.Text & "'"
       rsCon.Open iSQLStr, cnCon, adOpenStatic, adLockOptimistic, adCmdText
        rsCon.Fields("Group").Value = cmbGroup.Text
        rsCon.Fields("Label").Value = txtLabel.Text
        rsCon.Fields("Floor").Value = cmbFloor.Text
        rsCon.Fields("Wing").Value = cmbWing.Text
        rsCon.Fields("Mess").Value = cmbMess.Text
        rsCon.Fields("Trans").Value = cmbTrans.Text
      rsCon.Update
    MsgBox "Record Successfully updated", vbInformation 
    cnCon.Close


    Any guidance appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Why are you using vb code?...just put it in a query. odbc the table. No code needed.

  3. #3
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,418
    access 2007 (.accdb) uses ACE, not JET - so may be a reason.

    Interested in knowing your reasons for moving to ADO from DAO given it is more limited and you have to write your own filter and sort routines for forms and presumably reports.

    Also, since this is an update - why not just set the form recordset to the ADO recordset?

    Edit - Ah - just realised you are in VB6, not using Access coding, which might have an impact, but the arguments still stand

  4. #4
    Edward_ is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    38
    I solved it.

    My 'On error resume next' was masking an error in my SQL string.
    This new syntax corrected things.

    The SQL syntax correction solved the SQL error. (Both are numbers) My correct syntax is now.
    Code:
    iSQLStr = "SELECT * FROM tblData WHERE patID = " & cmbID.Text & " AND Num = " & cmbpatNum.Text & ""


    Thanks

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    The trailing & "" is not needed.
    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.

  6. #6
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,418
    just noticed an interesting difference between (access) vba and vb6.

    in vba the .text property is only available for the control which has the focus, in VB6, it appears to be available at any time

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    In VBA probably don't want Text property anyway. I've never used it. Value is the default property of data controls. Don't specify and Value will be used.

    iSQLStr = "SELECT * FROM tblData WHERE patID = " & Me.cmbID & " AND Num = " & Me.cmbpatNum
    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.

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

Similar Threads

  1. Syntax error (missing operator)
    By aamer in forum Access
    Replies: 5
    Last Post: 09-25-2014, 07:36 PM
  2. Replies: 2
    Last Post: 02-17-2014, 10:27 AM
  3. Replies: 13
    Last Post: 04-17-2013, 04:17 PM
  4. Syntax error missing operator(3075)
    By parisienne in forum Programming
    Replies: 1
    Last Post: 04-07-2011, 02:29 PM
  5. Syntax Error...missing operator
    By jgelpi16 in forum Programming
    Replies: 14
    Last Post: 09-09-2010, 11:35 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