RE: 2nd table need to add more fields other than from the 1st tabl
- From: "Curie" <Curie@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 23 Aug 2005 11:44:20 -0700
Here is my way to do in VBA. I have a sub that is called from another sub. It
receives passed parameters from the sub call. I declare some codes for
opening the record set as following,
------------------------------
Sub InsertDataToTBL2(intA As Integer, intB As Integer, intC As Integer, intD
As Integer)
Dim connectString As String
connectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = C:\Access\db1.mdb"
Dim myDB As ADODB.Connection
Set myDB = New ADODB.Connection
myDB.Open connectString
Dim rsTBL2 As ADODB.Recordset
Set rsTBL2 = New ADODB.Recordset
rsTBL2.Open "TBL2", myDB, adOpenDynamic, adLockOptimistic, adCmdTable
If Not rsTBL2.EOF And Not rsTBL2.BOF Then
Do Until rsTBL2.EOF
rsTBL2.MoveFirst
rsTBL2.Fields(0) = strValue
rsTBL2.Fields(1) = rsTBL1.Fields(1)
rsTBL2.Fields(2) = rsTBL1.Fields(2)
Loop
rsTBL2.MoveNext
End If
End Sub
-------------------------
>From the sub procedure that calls this sub procedure, I process each field
from TBL1. I want to assign values from TBL1 to TBL2. In addition, I need to
calculate some added fields in TBL2. In other word, TBL2 is a copy of TBL1
plus a couple more new fields with values that are calculated from TBL1's
data.
Anyway, when I run this sub, it does not enter into the loop and skip those
code. Do you know why it can not enter the loop. Also, the way I do, i.e.,
process each record from the first tbl and then call the second sub procedure
to put those data into TBL2 and then go back to do the 1st record...I suspect
it is not a good way to do. Do you have any idea to solve this problem?
Thank you,
Curie
"Klatuu" wrote:
> You will not need to use an array. There are a couple of methods you could
> use instead. One would be to manipulate the tables using VBA and
> programmatically add new records or update data in existing records of the
> second table. Another would be to construct either an append or an update
> query, depending on whether you are only adding new rows to table 2 (append)
> or modifiying data in table 2 (update). I am guessing it is adding new rows,
> so probably an append is in order. then for Update To row of the fields you
> need to add, do the calculation.
>
.
- Follow-Ups:
- References:
- 2nd table need to add more fields other than from the 1st table
- From: Curie
- RE: 2nd table need to add more fields other than from the 1st table
- From: Klatuu
- RE: 2nd table need to add more fields other than from the 1st tabl
- From: Curie
- RE: 2nd table need to add more fields other than from the 1st tabl
- From: Klatuu
- 2nd table need to add more fields other than from the 1st table
- Prev by Date: Re: Create Column/Table from multiple words in a field
- Next by Date: Re: incrementing records in linked subform
- Previous by thread: RE: 2nd table need to add more fields other than from the 1st tabl
- Next by thread: RE: 2nd table need to add more fields other than from the 1st tabl
- Index(es):
Relevant Pages
|