View Single Post
  #22  
Old August 10th, 2008, 09:20 PM posted to microsoft.public.access
[email protected]
external usenet poster
 
Posts: 87
Default SQL code works in Access SQL window but not in VBA SQL code

On Aug 10, 1:10*pm, "bcap" wrote:
"Michael Gramelspacher" wrote in message

...





On Sun, 10 Aug 2008 18:44:52 +0100, "bcap" wrote:


"Michael Gramelspacher" wrote in message
. ..
On Sun, 10 Aug 2008 09:30:25 -0700 (PDT),
wrote:


try this


dbs.Execute _
" a.AAA_UIC, a.ACRN, a.AMT, a.DOC_NUMBER, a.FIPC," & _
" a.REG_NUMB, a.TRAN_TYPE, a.DOV_NUM, a.PAA," & _
" a.COST_CODE, a.OBJ_CODE, a.EFY, a.REG_MO, a.RPT_MO," & _
" a.EFFEC_DATE, a.Orig_Sort, a.LTrim_BFY, a.LTrim_AAA," & _
" a.LTrim_REG, a.LTrim_DOV, a.AMT_Rev, a.CONCACT" & _
" INTO * [CHOOSERev] FROM * [CHOOSEData]" & _
" WHERE *(((a.TRAN_TYPE) IN ('1K','2D'))" & _
" AND ((a.LTrim_REG) '7'));"


How can he execute that string, it isn't even a statement? *There's no
SELECT...


Yes, of course. *Just a clerical error on my part, but not hard to correct
now that the error has
been pointed out.


Indeed not difficult to correct (sorry, I didn't actually look at your
string closely enough to realise that *only* the "SELECT" was missing).
Unfortunately, the OP's reply to you suggests that he tried to execute the
code *exactly* as you posted it.- Hide quoted text -

- Show quoted text -


Do I understand this correctly?


The user has opened Tool.mdb.

The ChooseData table exists ChooseData in Recon.

You want to dynamically create ChooseRev in Recon.

Within the Tools.mdb, please try this model:


Sub CopyData()

Dim sInsert As String
Dim sPathToRecon As String

sPathToRecon = "C:\TEMP\Recon.mdb"

sInsert = "SELECT ChooseData.* " _
& "INTO ChooseRev in " _
& Chr(34) & sPathToRecon & Chr(34) _
& "FROM ChooseData in " _
& Chr(34) & sPathToRecon & Chr(34)

DoCmd.SetWarnings 0
DoCmd.RunSQL (sInsert)
DoCmd.SetWarnings 1


End Sub