Results 1 to 5 of 5

Thread: [RESOLVED] [Access VBA] Error while saving

  1. #1

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Resolved [RESOLVED] [Access VBA] Error while saving

    Hi guys!!!

    I need help on Access.

    I cannot find where the error is.

    The error occurs during recordset.UpdateBatch and it says:

    Code:
    Invalid object name 'UPDATED'
    And what the hell does Recordset.UpdateBatch do?

    Thanks for any help you can give.
    Rate Me! Rate Me! Rate Me!

    Time to fly.

    Copyright GraysonSoft Inc. 2007

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: [Access VBA] Error while saving

    Check the help files but probably updates a batch of records.... guessing

    Does it tell you what line it errored on?
    Invalid object name 'UPDATED'
    Seems like you are trying to use an object that you haven't defined.

    Ensure you have tools>options>declare all variables ticked. (Puts option explicit at the top of the module and requires you to declare all variables you are using.)

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: [Access VBA] Error while saving

    Quote Originally Posted by Ecniv
    Check the help files but probably updates a batch of records.... guessing

    Does it tell you what line it errored on?

    Seems like you are trying to use an object that you haven't defined.

    Ensure you have tools>options>declare all variables ticked. (Puts option explicit at the top of the module and requires you to declare all variables you are using.)
    Nope. Still not working. Error mentioned above still works.
    Rate Me! Rate Me! Rate Me!

    Time to fly.

    Copyright GraysonSoft Inc. 2007

  4. #4

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: [Access VBA] Error while saving

    Can UpdateBatch add a new record?
    Rate Me! Rate Me! Rate Me!

    Time to fly.

    Copyright GraysonSoft Inc. 2007

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [Access VBA] Error while saving

    Hi

    Like Ecniv Suggested, If you browse thru the help file you will get see what update batch does
    In you Access VBA Help, Simply type "UpdateBatch"

    They also have a beautiful example on how to use the updatebatch command....

    er well, i'll paste the entire data from the help file here

    UpdateBatch Method
    Writes all pending batch updates to disk.

    Syntax
    recordset.UpdateBatch AffectRecords

    Parameters
    AffectRecords (Optional). An AffectEnum value that indicates how many records the UpdateBatch method will affect.

    Remarks
    Use the UpdateBatch method when modifying a Recordset object in batch update mode to transmit all changes made in a Recordset object to the underlying database.

    If the Recordset object supports batch updating, you can cache multiple changes to one or more records locally until you call the UpdateBatch method. If you are editing the current record or adding a new record when you call the UpdateBatch method, ADO will automatically call the Update method to save any pending changes to the current record before transmitting the batched changes to the provider. You should use batch updating with either a keyset or static cursor only.

    Note: Specifying adAffectGroup as the value for this parameter will result in an error when there are no visible records in the current Recordset (such as a filter for which no records match).
    If the attempt to transmit changes fails for any or all records because of a conflict with the underlying data (for example, a record has already been deleted by another user), the provider returns warnings to the Errors collection and a run-time error occurs. Use the Filter property (adFilterAffectedRecords) and the Status property to locate records with conflicts.

    To cancel all pending batch updates, use the CancelBatch method.

    If the Unique Table and Update Resync dynamic properties are set, and the Recordset is the result of executing a JOIN operation on multiple tables, then the execution of the UpdateBatch method is implicitly followed by the Resync method depending on the settings of the Update Resync property.

    The order in which the individual updates of a batch are performed on the data source is not necessarily the same as the order in which they were performed on the local Recordset. Update order is dependent upon the provider. Take this into account when coding updates that are related to one another, such as foreign key constraints on an insert or update.

    Example


    UpdateBatch and CancelBatch Methods Example (VB)

    This example demonstrates the UpdateBatch method in conjunction with the CancelBatch method.

    vb Code:
    1. 'BeginUpdateBatchVB
    2. Public Sub Main()
    3.     On Error GoTo ErrorHandler
    4.  
    5.     'To integrate this code
    6.     'replace the data source and initial catalog values
    7.     'in the connection string
    8.  
    9.     'connection and recordset variables
    10.     Dim rstTitles As ADODB.Recordset
    11.     Dim Cnxn As ADODB.Connection
    12.     Dim strCnxn As String
    13.     Dim strSQLTitles As String
    14.      'record variables
    15.     Dim strTitle As String
    16.     Dim strMessage As String
    17.    
    18.     ' Open connection
    19.     Set Cnxn = New ADODB.Connection
    20.     strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _
    21.         "Initial Catalog='Pubs';Integrated Security='SSPI';"
    22.     Cnxn.Open strCnxn
    23.    
    24.      ' open recordset for batch uodate
    25.     Set rstTitles = New ADODB.Recordset
    26.     strSQLTitles = "titles"
    27.     rstTitles.Open strSQLTitles, Cnxn, adOpenKeyset, adLockBatchOptimistic, adCmdTable
    28.    
    29.     rstTitles.MoveFirst
    30.     ' Loop through recordset and ask user if she wants
    31.     ' to change the type for a specified title.
    32.     Do Until rstTitles.EOF
    33.         If Trim(rstTitles!Type) = "psychology" Then
    34.             strTitle = rstTitles!Title
    35.             strMessage = "Title: " & strTitle & vbCr & _
    36.                "Change type to self help?"
    37.            
    38.             If MsgBox(strMessage, vbYesNo) = vbYes Then
    39.                 rstTitles!Type = "self_help"
    40.             End If
    41.         End If
    42.    
    43.         rstTitles.MoveNext
    44.     Loop
    45.    
    46.     ' Ask the user if she wants to commit to all the
    47.     ' changes made above.
    48.     If MsgBox("Save all changes?", vbYesNo) = vbYes Then
    49.         rstTitles.UpdateBatch
    50.     Else
    51.         rstTitles.CancelBatch
    52.     End If
    53.    
    54.     ' Print current data in recordset.
    55.     rstTitles.Requery
    56.     rstTitles.MoveFirst
    57.     Do While Not rstTitles.EOF
    58.         Debug.Print rstTitles!Title & " - " & rstTitles!Type
    59.         rstTitles.MoveNext
    60.     Loop
    61.    
    62.     ' Restore original values because this is a demonstration.
    63.     rstTitles.MoveFirst
    64.     Do Until rstTitles.EOF
    65.         If Trim(rstTitles!Type) = "self_help" Then
    66.             rstTitles!Type = "psychology"
    67.         End If
    68.         rstTitles.MoveNext
    69.     Loop
    70.     rstTitles.UpdateBatch
    71.  
    72.     ' clean up
    73.     rstTitles.Close
    74.     Cnxn.Close
    75.     Set rstTitles = Nothing
    76.     Set Cnxn = Nothing
    77.     Exit Sub
    78.    
    79. ErrorHandler:
    80.     ' clean up
    81.     If Not rstTitles Is Nothing Then
    82.         If rstTitles.State = adStateOpen Then rstTitles.Close
    83.     End If
    84.     Set rstTitles = Nothing
    85.    
    86.     If Not Cnxn Is Nothing Then
    87.         If Cnxn.State = adStateOpen Then Cnxn.Close
    88.     End If
    89.     Set Cnxn = Nothing
    90.    
    91.     If Err <> 0 Then
    92.         MsgBox Err.Source & "-->" & Err.Description, , "Error"
    93.     End If
    94. End Sub
    95. 'EndUpdateBatchVB

    Hope this helps...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width