PC Review


Reply
Thread Tools Rate Thread

Add recordset data to local linked table.

 
 
New Member
Join Date: Jul 2012
Posts: 1
 
      12th Jul 2012
Using MS Access VBA -- 2010:

I am trying to add a recordset to an existing table (linked).
Bkground:
I have a query that gives me a list of all records from two sources, share pt table and a spreadsheet, where the SeraialNumbers are identical.
I then display a list of matches, select specific ones from Listbox
then fill a recordset with the whole share pt record.
OK so far ...
Now I want to make a copy of the share pt record into a local table for backup,
then delete the record from share pt.

I thought I could use the recordset to copy the record directly into a local linked table.
I am stuck at coping the record.

Note: Share pt table is inventory, The spreadsheet is a salvage list .. I periodically
purge the inventory based on the salvage list.
I wanted to stream line the process.
This is what I have:
*************************************************************************************************
Private Sub cmdCpySel_Item_Click()
Dim sItem_idx As Variant
Dim sItem As Variant
Dim strSQL As String
Dim rstTable As Recordset


Set MyDB = CurentDb

Set rstTable = MyDB.OpenRecordset("Deleted Rec InventoryPC", dbOpenTable)


For Each sItem_idx In List1.ItemsSelected

sItem = List1.ItemData(sItem_idx)
MsgBox sItem, vbOKOnly, "Selected.."
'Now.. find sItem in Inventory db and get whole record...

strSQL = "SELECT * FROM Inventory WHERE (Inventory.[Service Tag] = " & Chr(34) & sItem & Chr(34) & ")"
'Set MyRec = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)

MsgBox strSQL, vbOKOnly, "Query.."

'DoCmd.RunSQL strSQL
Set MyRec = CurrentDb.OpenRecordset(strSQL, dbOpenForwardOnly)

'Display results...

'Must first tell the list bx how many column's (fields) you have ...
List7.ColumnCount = MyRec.Fields.Count
'Now you can point the List at your source (SQL statement)
List7.RowSource = strSQL

'now .. add record to a local table .. for bkup.
rstTable.AddNew = MyRec 'Compile ERROR Expected fn or variable'


'Then delete record from share pt.


Next sItem_idx
Set MyRec = Nothing
Set rstTable = Nothing

End Sub


*************************
any ideas?
 
Reply With Quote
 
 
 
 
New Member
Join Date: Aug 2012
Posts: 2
 
      27th Aug 2012
Quote:
'now .. add record to a local table .. for bkup.
rstTable.AddNew = MyRec 'Compile ERROR Expected fn or variable'
Pretty certain AddNew is a function so usage would be rstTable.AddNew(MyRec)

If that still fails you may have to produce a clone of the record as it does not belong to the recordset your adding it to.

Hope this helps ...
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2007 - Copy linked table to a local table or have linked tableas read-only Stuart Microsoft Access 0 26th May 2012 10:28 PM
Problem adding local user to local group or deleting local user fkitzmann Microsoft Windows 2000 4 16th Feb 2008 04:02 AM
Cannot add form.recordset to adodb.recordset =?Utf-8?B?VG9yZQ==?= Microsoft Access ADP SQL Server 10 1st Jun 2007 10:50 PM
How to convert recordset of only PKs into full field recordset? Bam Bam Microsoft Access 3 4th Oct 2004 04:04 AM
Type recordset/recordset? FlaviusFlav Microsoft Excel Programming 4 24th May 2004 12:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:49 AM.