View Single Post
  #2  
Old January 8th 06, 05:07 AM posted to microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.outlook.program_vba
Allen Browne
external usenet poster
 
Posts: 4
Default Running query from Access Form commmand using VBA code

What result are you getting? Error message? Nothing at all?

One of the problems with RunSQL is that, if you turn off SetWarnings, you
get no indication if something goes wrong. Instead of:
DoCmd.SetWarnings False
DoCmd.RunSQL strSql
try:
dbEngine(0)(0).Execute strSql, dbFailOnError
That will not bother you with a confirmation dialog, but will generate a
trappable error if the insert fails.

The values you are inserting into PdWoDesc2 and PdWoDesc3 involve IIf()
expressions. Because of the way the lines broke, I cannot tell if you are
trying to insert a space of a zero-length string for the final option, but
this could be the cause of the failure. Try inserting a Null instead:
IIf(Len(RTrim(tblReviewWorkOrders!WoDesc))40,
Trim(Mid(tblReviewWorkOrders!WoDesc,41,60)), Null) AS WoDesc2,

You could also make it more efficient by removing the Left() from the WHERE
clause for the WoNo field, i.e. change:
((Left([tblReviewWorkOrders]![WoNo],1)) Like "l" Or
to:
([tblReviewWorkOrders]![WoNo],1 Like "l*" Or
and the same for "m*" and "v*". If the WoNo field happens to be indexed, JET
will be able to use the index if the function call is not there.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Berny" BlancoB at MSN dot Com wrote in message
...
I'm trying to run an append query using VBA code but can seem to get it to
work.

Can someone tell me if this is even possible?

Below is the query I'm trying to run:

INSERT INTO tblPastDueUpload ( PdWoNo, PdWoDesc1, PdWoDesc2, PdWoDesc3,
PdDateChk, PdPty, PdWoCls )
SELECT tblReviewWorkOrders.WoNo, Left(tblReviewWorkOrders!WoDesc,40) AS
WoDesc1,
IIf(Len(RTrim(tblReviewWorkOrders!WoDesc))40,Mid( tblReviewWorkOrders!WoDesc,41,60),"
") AS WoDesc2,
IIf(Len(RTrim(tblReviewWorkOrders!WoDesc))100,Mid (tblReviewWorkOrders!WoDesc,101,60),"
") AS WoDesc3,
IIf(tblReviewWorkOrders!EstComp(Date()+30),(Date( )+45),tblReviewWorkOrders!EstComp)
AS DateChk, tblReviewWorkOrders.Pty, IIf([ActHrs]20,"B",[SrvCat]) AS
WoCls
FROM tblReviewWorkOrders
WHERE (((tblReviewWorkOrders.Bklg)="ad3") AND
((tblReviewWorkOrders.Status)"07") AND
((tblReviewWorkOrders.EstComp)Date()) AND
((tblReviewWorkOrders.TotalCost)[tblReviewWorkOrders]![Authorized]-50)
AND ((tblReviewWorkOrders.blnExclude)=0) AND
((Left([tblReviewWorkOrders]![WoNo],1)) Like "l" Or
(Left([tblReviewWorkOrders]![WoNo],1))="m" Or
(Left([tblReviewWorkOrders]![WoNo],1))="v") AND
((tblReviewWorkOrders.CatCode) Not Like "*pwo*") AND
((tblReviewWorkOrders.UserField2) Not Like "wp*"))
ORDER BY tblReviewWorkOrders.WoNo;

I was trying to use code similar to below but can get it to work

strSql = ***I can't get any code in this area to work, any suggestions?
***
DoCmd.SetWarnings False
DoCmd.RunSQL strSql

Any help would be greatly appreciated.



Ads