A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Running query from Access Form commmand using VBA code



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 8th 06, 03:37 AM posted to microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.outlook.program_vba
Berny
external usenet poster
 
Posts: 3
Default Running query from Access Form commmand using VBA code

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.




  #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.



  #3  
Old January 16th 06, 12:57 AM posted to microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.outlook.program_vba
Berny
external usenet poster
 
Posts: 3
Default Running query from Access Form commmand using VBA code

I was trying to create an append query on the fly instead of using a regular
query


"Allen Browne" wrote in message
...
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.





  #4  
Old January 16th 06, 05:31 AM posted to microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.outlook.program_vba
TC
external usenet poster
 
Posts: 1
Default Running query from Access Form commmand using VBA code

Berny, Allen is saying that: "can't seem to get it to work" is not
enough for us to go on. Are you getting an error message? If so, what
is that message? Have you checked SetWarnings, as he suggested?

HTH,
TC [MVP Access]

  #5  
Old January 16th 06, 02:12 PM posted to microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.outlook.program_vba
Berny
external usenet poster
 
Posts: 3
Default Running query from Access Form commmand using VBA code

I changed my approach to this problem and posted my new problem under the
Queries Group (I thought it was a more appropriate group)

By the way Allen is also helping me with my new problem

MANY Thanks!

Your Help is Greatly Appreciated

"TC" wrote in message
oups.com...
Berny, Allen is saying that: "can't seem to get it to work" is not
enough for us to go on. Are you getting an error message? If so, what
is that message? Have you checked SetWarnings, as he suggested?

HTH,
TC [MVP Access]



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA shortcut to open custom form in design mode? Burma Jones Outlook - Using Forms 2 March 6th 06 07:17 PM
Outlook not displaying attachment from Access via code [email protected] Outlook - General Queries 4 February 27th 06 11:30 PM
how to apply vba code to OL2003 forms ? TimR Outlook - Using Contacts 1 February 17th 06 04:41 PM
Delete Custom Outlook Control thru Access VBA Sue Mosher [MVP-Outlook] Outlook - Using Forms 0 January 20th 06 05:29 PM
Need code for appointment form Colin Coady Outlook - Using Forms 0 January 18th 06 01:21 PM


All times are GMT +1. The time now is 09:50 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.