473,386 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Declare sql or not?

Hi,

Should I:

--------------------
Dim sqlA As String
sqlAll = "DELETE * FROM tblName;" '....or whatever!
DoCmd.RunSQL sqlA
--------------------

Or is it acceptable to just:
--------------------
DoCmd.RunSQL (DELETE * FROM tblName;)
--------------------

I know both work, but is there a reason I should use one over the
other?

Thanks, Jon

Aug 27 '06 #1
3 2358
"J-P-W" <jo******@gmail.comwrote in
news:11**********************@i42g2000cwa.googlegr oups.com:
Hi,

Should I:

--------------------
Dim sqlA As String
sqlAll = "DELETE * FROM tblName;" '....or whatever!
DoCmd.RunSQL sqlA
--------------------

Or is it acceptable to just:
--------------------
DoCmd.RunSQL (DELETE * FROM tblName;)
--------------------

I know both work, but is there a reason I should use one over
the
other?

Thanks, Jon
That depends on the length of the SQL statement. I put short
commands directly into the runSQL().

However, I have code where the sql statement runs to 10,000
characters. By building it in increments it's a lot easier to
debug. I've even resorted to split a statement into sections
Dim sqlSelect as string, sqlFrom as string,
Dim sqlWhere as string, sqlORder as string

then doing
DoCmd.RunSQL(sqlSelect & " " & sqlFrom & " " & sqlWhere)

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 27 '06 #2
As long as you add the quotes, you can use:
DoCmd.RunSQL "DELETE FROM tblName;"

For such as simple query, there is not really a point to declaring a string.
For a more complex query statement where you are concatenating values into
the string, declaring a string aids:
a) readability: you can see what's going on, and
b) debugging: you can:
Debug.Print strA

A more important issue is whether the query ran to completion or not. The
Execute method gives you much more flexibilty that RunSQL. Details in:
Action queries: suppressing dialogs, while knowing results
at:
http://allenbrowne.com/ser-60.html

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

"J-P-W" <jo******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>
Should I:

--------------------
Dim sqlA As String
sqlAll = "DELETE * FROM tblName;" '....or whatever!
DoCmd.RunSQL sqlA
--------------------

Or is it acceptable to just:
--------------------
DoCmd.RunSQL (DELETE * FROM tblName;)
--------------------

I know both work, but is there a reason I should use one over the
other?

Aug 27 '06 #3

Allen Browne wrote:
As long as you add the quotes, you can use:
DoCmd.RunSQL "DELETE FROM tblName;"

For such as simple query, there is not really a point to declaring a string.
For a more complex query statement where you are concatenating values into
the string, declaring a string aids:
a) readability: you can see what's going on, and
b) debugging: you can:
Debug.Print strA

A more important issue is whether the query ran to completion or not. The
Execute method gives you much more flexibilty that RunSQL. Details in:
Action queries: suppressing dialogs, while knowing results
at:
http://allenbrowne.com/ser-60.html

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

"J-P-W" <jo******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...

Should I:

--------------------
Dim sqlA As String
sqlAll = "DELETE * FROM tblName;" '....or whatever!
DoCmd.RunSQL sqlA
--------------------

Or is it acceptable to just:
--------------------
DoCmd.RunSQL (DELETE * FROM tblName;)
--------------------

I know both work, but is there a reason I should use one over the
other?
Thank you, So what I've been doing is fine then...using which ever
methode seemed best at the time!!

Regards

Jon

Aug 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Derrick | last post by:
How does one declare an event within an interface, so that every class which implements that interface must implement that event? I think I just need to specifiy the actual event as I would a...
5
by: Jiggaz | last post by:
Hi, Look my stored procedure : __________________ ALTER PROCEDURE dbo.CreateAccount @Nickname varchar(30), @Password varchar(15), @Email varchar(50), @Date datetime,
2
by: Lance Geeck | last post by:
I have many items that I lifted off from Microsoft's website several years ago. These samples were in VB6. I now want to convert an application to VB.NET. I am getting an error that says "As Any...
10
by: Bob Hollness | last post by:
Hi all. I have a Sub that calls another sub. Both subs use a common object, so I used Public to declare it at the top of the module, as below. Public Writer As StreamWriter =...
1
by: marfi95 | last post by:
I'm trying to call methods in a C++ dll from vb.net that is not a .com component. I've read I can just use regular Declare statements just as you do in VB6 except that some of the types need to...
6
by: **Developer** | last post by:
Notice below I sometimes used the "A" version. I found by cut-and-try that only the "A" version would work correctly. Anyone have a suggestion of why the "W" version would not work correctly? ...
6
by: John Bailo | last post by:
I created a sproc with 3 input parameters and one output parameter. I want to test it in the "Run SQL Scripts" app of Navigator. I wrote this code: DECLARE RTNDATE CHAR(10) DEFAULT ''; CALL...
2
by: juan.gautier | last post by:
Hi, I try to construct a SQL code for a view to select a specific data from a table, this query take the value of the filter from a text box in a visual basic 6.0 form. my problem is when i...
1
by: ares.lagae | last post by:
- I have a typelist and I want to declare a member variable for each of the types. How can I do that? E.g. I have the typelist "typedef boost::mpl::vector<int, float> types;" and I want to declare...
1
by: okonita | last post by:
Hi all, My environment is DB2 UDBv8.2 on Windows and Linux. I am getting a lot of errors on the script you see below. Some of the error I am geting are: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.