473,405 Members | 2,187 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,405 software developers and data experts.

how to write sql query in VBA

I have form on which there are three text boxes first is start date, second is end date and third is type
I am trying to write sql query in VBA to fetch data which is sum of inspection_Planned between two date(start date and end date)and then of particular type.
I have written following code to do it
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. Dim rs As Recordset
  3.  
  4. Set db = CurrentDb
  5.  
  6. strSQL = "SELECT SUM(Inspection_Planned) From tblauditplanned WHERE ([Inspection_Palnned_Dte] Between " & Me.txtddjansd & " And " & Me.txtddjaned & ") AND [Inspection_Type] = ' & cmbsarepinsptype & ' "
  7. Set rs = db.OpenRecordset(strSQL)
  8. txtsarepjan1 = rs.Fields(0)
  9.  
i am having this code on button and on click of that button query does not produce result neither gives error
plz help
thanks
Dec 30 '13 #1
2 4109
Rabbit
12,516 Expert Mod 8TB
I'm surprised you don't get any errors. I see at least 3.

1) Date literals need to be surrounded by pound (#) symbols.
2) I'm pretty sure this is spelled incorrectly: Inspection_Palnned_Dte. Either that or it was originally spelled incorrectly in the table.
3) Your cmbsarepinsptype is within the string and so has become a literal and is not returning the actual value of the combobox.
Dec 30 '13 #2
NeoPa
32,556 Expert Mod 16PB
See Literal DateTimes and Their Delimiters (#).

A good way to debug SQL is to take the resulting SQL from the string and try it in a QueryDef. QueryDefs have three views :
  1. Design view - which shows you the design in a grid.
  2. Datasheet view - which shows you the results. For an action query it shows you what will be affected.
  3. SQL view - which shows you (and allows you to modify directly) the SQL of the query.
You need to paste the SQL resulting from your code into the SQL view of a new query to see what it does. If it fails it generally gives more helpful messages than simply opening a recordset based on it from your code.
Dec 30 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tanamon | last post by:
Hello All, I am a MySQL newbie trying to write a query that selects file_name records possessing the highest numbered version for that unique file_name. I show sample data and two trial queries...
3
by: Simon Gare | last post by:
Hi All, having a problem with the error "Either BOF or EOF is True, or the current record has been deleted. " found a workaround that allows the non existent data to be bypassed and insert a 0...
5
by: GreggaR0und | last post by:
Hello; I am trying to use Access VBA to write each record in a query to its own individual XML file. That is, each record represents one XML file which will then be sent to a SharePoint Form...
2
by: Himmel | last post by:
Hello! The reference database I currently use runs queries that pull data from hundreds of tables in order to create user-friendly form view. The problem is that these queries can take upwards of...
0
by: sachjn | last post by:
Hi, I have three tables with columns as: Person_sys1 Id(pk) name telephoneNum userid ----- -------- ---------------------- --------- Person_sys2 Id(pk) name ...
0
by: sara | last post by:
Hi - I have a table keeping track of employees' jobs in a location. So, Store #1 Manager #353, AsstMgr #556 Store #2 Manager #776, AsstMgr #132 etc. The table is Date StoreNum MgrNum ...
0
by: xwebmaster | last post by:
Hi Please help me solving this query.. I have 3 tables.. comm_propDB ID | User_ID | mls_num -----|---------------|--------------------- 2 | 2 | 5004 3 | 2 ...
4
by: micropos | last post by:
hi everyone,who can help me solve the problem?this is my code: <?php include 'C:/wamp/www/micropos/condb1.php'; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could...
5
by: vishal prada | last post by:
ResultSet res = st.executeQuery("select * from regist where Password='"+User_Password+"'"); if(res.next()==true) { ps = con.prepareStatement("update regist set Password=?,...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.