|
-
Mar 28th, 2007, 10:51 PM
#1
Thread Starter
Hyperactive Member
[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
-
Mar 29th, 2007, 02:04 AM
#2
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.)
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...
-
Mar 29th, 2007, 03:31 AM
#3
Thread Starter
Hyperactive Member
Re: [Access VBA] Error while saving
 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
-
Mar 29th, 2007, 03:32 AM
#4
Thread Starter
Hyperactive Member
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
-
Mar 29th, 2007, 04:24 PM
#5
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:
'BeginUpdateBatchVB
Public Sub Main()
On Error GoTo ErrorHandler
'To integrate this code
'replace the data source and initial catalog values
'in the connection string
'connection and recordset variables
Dim rstTitles As ADODB.Recordset
Dim Cnxn As ADODB.Connection
Dim strCnxn As String
Dim strSQLTitles As String
'record variables
Dim strTitle As String
Dim strMessage As String
' Open connection
Set Cnxn = New ADODB.Connection
strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _
"Initial Catalog='Pubs';Integrated Security='SSPI';"
Cnxn.Open strCnxn
' open recordset for batch uodate
Set rstTitles = New ADODB.Recordset
strSQLTitles = "titles"
rstTitles.Open strSQLTitles, Cnxn, adOpenKeyset, adLockBatchOptimistic, adCmdTable
rstTitles.MoveFirst
' Loop through recordset and ask user if she wants
' to change the type for a specified title.
Do Until rstTitles.EOF
If Trim(rstTitles!Type) = "psychology" Then
strTitle = rstTitles!Title
strMessage = "Title: " & strTitle & vbCr & _
"Change type to self help?"
If MsgBox(strMessage, vbYesNo) = vbYes Then
rstTitles!Type = "self_help"
End If
End If
rstTitles.MoveNext
Loop
' Ask the user if she wants to commit to all the
' changes made above.
If MsgBox("Save all changes?", vbYesNo) = vbYes Then
rstTitles.UpdateBatch
Else
rstTitles.CancelBatch
End If
' Print current data in recordset.
rstTitles.Requery
rstTitles.MoveFirst
Do While Not rstTitles.EOF
Debug.Print rstTitles!Title & " - " & rstTitles!Type
rstTitles.MoveNext
Loop
' Restore original values because this is a demonstration.
rstTitles.MoveFirst
Do Until rstTitles.EOF
If Trim(rstTitles!Type) = "self_help" Then
rstTitles!Type = "psychology"
End If
rstTitles.MoveNext
Loop
rstTitles.UpdateBatch
' clean up
rstTitles.Close
Cnxn.Close
Set rstTitles = Nothing
Set Cnxn = Nothing
Exit Sub
ErrorHandler:
' clean up
If Not rstTitles Is Nothing Then
If rstTitles.State = adStateOpen Then rstTitles.Close
End If
Set rstTitles = Nothing
If Not Cnxn Is Nothing Then
If Cnxn.State = adStateOpen Then Cnxn.Close
End If
Set Cnxn = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
'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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|