Dear Dirk
This is a continuation of my last mail where I tried to combine to equal
commands for to different tables in one command button.
Here you will find the code I tried to write.
*At first I got the error message: Compile error, Duplicate declaration in
current scope. - I took the duplicate out
* than I got the next error message: Syntax error in INSERT INTO statement.
Please have a look at the code and maybe you can tell what I am doing wrong.
Many thanks in advance
Klaus
**************************CODE**************************
Private Sub cmdTransfer_Click()
On Error GoTo Err_Handler
Dim strTargetDB As String
Dim strTargetTable As String
Dim strSQL As String
strTargetDB = "C:\Documents and Settings\Klaus
Müller\Desktop\cps207\transferdb.mdb"
strTargetTable = "webtotalbalancebie30p"
With CurrentDb
strSQL = _
"DELETE FROM [" & strTargetTable & "] " & _
"IN '" & _
strTargetDB & "';"
.Execute strSQL, dbFailOnError
strSQL = _
"INSERT INTO [" & strTargetTable & _
"] (accountnumber, initialinvestment, guaranteedequity,
monthstartingbalance, SumOfcontractvalue, commission, managementfeebasic,
Incentivefeetotal, electronicfee, vat, adjustment, netliquidationbalance,
SumOfopenpl, SumOfinitialmargin, SumOfmaintenancemargin, opentradebalance) IN
'" & _
strTargetDB & _
"' SELECT webtotalbalancebie30p.accountnumber,
webtotalbalancebie30p.initialinvestment,
webtotalbalancebie30p.guaranteedequity,
webtotalbalancebie30p.monthstartingbalance,
webtotalbalancebie30p.SumOfcontractvalue, webtotalbalancebie30p.commission,
webtotalbalancebie30p.managementfeebasic,
webtotalbalancebie30p.incentivefeetotal, webtotalbalancebie30p.electronicfee,
webtotalbalancebie30p.vat, webtotalbalancebie30p.adjustment,
webtotalbalancebie30p.netliquidationbalance,
webtotalbalancebie30p.SumOfopenpl, webtotalbalancebie30p.SumOfinitialmargin,
webtotalbalancebie30p.SumOfmaintenancemargin,
webtotalbalancebie30p.opentradebalance " & _
"FROM webtotalbalancebie30p;"
CurrentDb.Execute strSQL, dbFailOnError
End With
strTargetDB = "C:\Documents and Settings\Klaus
Müller\Desktop\cps207\transferdb.mdb"
strTargetTable = "weboffsetordersbie30p"
With CurrentDb
strSQL = _
"DELETE FROM [" & strTargetTable & "] " & _
"IN '" & _
strTargetDB & "';"
.Execute strSQL, dbFailOnError
strSQL = _
"INSERT INTO [" & strTargetTable & _
"] (tradeid, clearingnumber, date, bought, sold, commodity,
month, year, price, contractvalue) IN '" & _
strTargetDB & _
"' SELECT weboffsetordersbie30p.tradeid,
weboffsetordersbie30p.clearingnumber, weboffsetordersbie30p.date,
weboffsetordersbie30p.bought, weboffsetordersbie30p.sold,
weboffsetordersbie30p.commodity, weboffsetordersbie30p.month,
weboffsetordersbie30p.year, weboffsetordersbie30p.price,
weboffsetordersbie30p.contractvalue " & _
"FROM weboffsetordersbie30p;"
CurrentDb.Execute strSQL, dbFailOnError
End With
Exit_Point:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End Sub
****************************************************
Dirk Goldgar said:
Amateur said:
Dear Dirk
Now nothing is working anymore.
Ah, I see we're making progress! <g>
Seriously, you have to tell us what you mean when you say "nothing is
working". What happens? Do you get an error message? If so, what
exactly is the message (and number, if available)? Without that
information, we can only guess what may be wrong. We're not
clairvoyant.
That said, I believe I see an error in the code you posted, though it
mostly looks okay to me, not "totally wrong". But this line:
"] (accountnumber, initialinvestment, guaranteedequity, ) IN '" &
_
.... has a syntax error. There should be no trailing comma within the
parentheses. That should be:
"] (accountnumber, initialinvestment, guaranteedequity) IN '" & _
Fix that, and then tell me whether it works or not. If it doesn't work,
please give a full description of the error.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)