![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
DoCmd.RunSql strSql |
#4
| |||
| |||
|
|
Rich P <rpng... (AT) aol (DOT) com> wrote: DoCmd.RunSql strSql The problem with *DoCmd.RunSQ is that it ignores any errors. *Either of the following will display any error messages received by the query. *If using DAO, use Currentdb.Execute strSQL,dbfailonerror.. *For ADO use CurrentProject.Connection.Execute strCommand, lngRecordsAffected, adCmdText * *You can then remove the docmd.setwarnings lines. If you're going to use docmd.setwarnings make very sure you put the True statement in any error handling code as well. * Otherwise weird things may happen later on especially while you are working on the app. *For example you will no longer get the "Do you wish to save your changes" message if you close an object. *This may mean that unwanted changes, deletions or additions will be saved to your MDB. Also performance can be significantly different between the two methods. *One posting stated currentdb.execute took two seconds while docmd.runsql took eight seconds. *As always YMMV. Tony -- Tony Toews, Microsoft Access MVP * *Please respond only in the newsgroups so that others can read the entire thread of messages. * *Microsoft Access Links, Hints, Tips & Accounting Systems athttp://www.granite.ab.ca/accsmstr.htm * *Tony's Microsoft Access Blog -http://msmvps.com/blogs/access/ |
#5
| |||
| |||
|
|
Hi Sara, If you try it this way - you may have better luck Dim strSql As String strSql = "INSERT INTO tblPOCancels ( PONum, PODate, DateEntered, MerchantKey,VendorKey, POApproved, " _ *& "SuggShipDate, Description, CostofGoods, Freight, TotalRetail, PODatetoStores, DeptNum, Reason) " _ *& "Select " & txtPOnum & ", #" & txtPODate & "#, #" & txtDateEntered & "#, '" & txtMerchantKey & _ *& "', '" & txtVendorKey & "', '" & txtApproved & "', #" & txtShippedDate & "#, '" & txtDescription & "', " _ *& txtCostOfGoods & ", " & txtFreight & ", *" & txtTotalRetail & ", #" & txtPostDateToStores & "#, " _ *& txtDeptNum & ", '" & txtReason & "'" DoCmd.RunSql strSql You can place this code in a command button on the form itself. *I delimited your values as follows - number value do not require delimiting. *Date values (for Access Jet sql) require a # symbol for delimiting - and text values (reason, Description, ...) require a single apostrophe ' for delimiting. *Also, the string above appears all jumbled up. *If you copy this into notepad to unscramble it - the strings are all broken at _ & * the underscore defines the end of the string and the ampersand defines the beginning of the next string. *Once you clean it up - copy it into the Form button's code module. *Hopefully you wont get any red. *Thenit should work. HTH Rich *** Sent via Developersdexhttp://www.developersdex.com*** |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
But if you are just a regular human - docmd.runsql is a bit simpler than currentdb.execute. |
#8
| |||
| |||
|
#9
| |||
| |||
|
#10
| |||
| |||
|
|
Rich P <rpng... (AT) aol (DOT) com> wrote innews:48eb9194$0$89390$815e3792 (AT) news (DOT) qwest.net: if you are just a regular human - docmd.runsql is a bit simpler than currentdb.execute. How about this, which is going to be just as easy to use as DoCmd.RunSQL and will be safer, and have the added bonus of requiring only one line of code to use (instead of three from futzing around with SetWarnings): Public Function RunSQL(strSQL As String) As Boolean On Error GoTo errHandler CurrentDB.Execute strSQL, dbFailOnError RunSQL = True exitRoutine: Exit Function errHandler: MsgBox err.Number & ": " & err.Description, vbExclamation, _ "Error in Function RunSQL()" Resume exitRoutine End Function -- David W. Fenton http://www.dfenton.com/ usenet at dfenton dot com http://www.dfenton.com/DFA/ |
![]() |
| Thread Tools | |
| Display Modes | |
| |