473,385 Members | 1,492 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,385 software developers and data experts.

Convert SQL code to VBA code

2
Hello all,

I have been trying to solve this issue for a while now and could really use some help!
Basically, I am trying to convert a SQL code into VBA but I'm having some issues with the piece below:

Expand|Select|Wrap|Line Numbers
  1. FROM HISTORY.dbo.tbl_Data
  2.  
  3. Where
  4. Week_Ending = 'WE080611'
  5. AND Facility IN ('Hartford, CT')
  6. AND (Ledgend LIKE 'DEL')
  7. AND [Cust_#] IN ('12345')
  8.  
  9. ) i
  10.  
  11. GROUP BY DayofWeek
  12. ) j


In my excel file, I have a few drop down boxes and list boxes which I use to update the fields (except for the Ledgend part). I've already put together the majority of the code I'm just stuck on this one piece. Any help would be appreciated! Here's what I have right now..

Expand|Select|Wrap|Line Numbers
  1. "FROM HISTORY.dbo.tbl_Data" & _
  2.  
  3. "WHERE [Facility] = '" & Facility & "' and [Week_Ending] = '" & WeekEnd & "' and (Ledgend LIKE 'DEL') AND [Route #] IN " & _
  4. "( SELECT DISTINCT [Route #] FROM HISTORY.dbo.tbl_Data WHERE " & _
  5. WhereStr & " AND (Ledgend LIKE 'DEL') " & _
  6.  
  7. ") k" & _
  8. "GROUP BY DayofWeek" & _
Sep 22 '11 #1
3 3982
ADezii
8,834 Expert 8TB
The Basic SQL would look something like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tbl_Data
  2. WHERE tbl_Data.Week_Ending="WE080611" 
  3. AND tbl_Data.Facility In ('Hartford, CT') 
  4. AND tbl_Data.Ledgend Like "*Del*" 
  5. AND tbl_Data.[Cust_#] In ('12345');
Sep 22 '11 #2
Ryan H
2
Thanks for responding ADezii, I already have the SQL code in place though and it right now it's working like it should. It's when I'm trying to convert that code into VBA that's the issue. I'm by no means an expert in VBA but I think I've narrowed down the issue to the piece of code above.
Sep 23 '11 #3
ADezii
8,834 Expert 8TB
Here is a functional example of how you can convert the SQL Code to VBA:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. Dim MyDB As DAO.Database
  3. Dim rst As DAO.Recordset
  4.  
  5. strSQL = "SELECT * FROM tbl_Data WHERE tbl_Data.Week_Ending = 'WE080611' AND " & _
  6.          "tbl_Data.Facility In ('Hartford, CT') AND tbl_Data.Ledgend Like '*Del*' " & _
  7.          "AND tbl_Data.[Cust_#] In ('12345');"
  8.  
  9. Set MyDB = CurrentDb
  10. Set rst = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
  11.  
  12. rst.MoveFirst
  13.  
  14. With rst
  15.   Do Until .EOF
  16.     Debug.Print ![Week_Ending], ![Facility], ![Ledgend], ![Cust_#], ![DayOfWeek]
  17.      .MoveNext
  18.   Loop
  19. End With
  20.  
  21. If Not rst Is Nothing Then
  22.   rst.Close
  23.     Set rst = Nothing
  24. End If
Sep 23 '11 #4

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

Similar topics

26
by: sam | last post by:
Hi, Can anyone help me find a software that can convert a code in 'C' to 'Fortran77/90' automatically? Thanks in advance. Sam.
1
by: New Devil | last post by:
Hi all, Can anybody help me to convert this code from VB to C#....i got this code from msdn but i want to do this in C# .... plz help if u can....thanx the code is......
2
by: Striped | last post by:
Is there any tool to convert source code, e.g. of a C# method, to opcodes being used in System.Reflection.Emit? It's a real pain to do that manually, especially for big pieces of code. public...
3
by: Ian | last post by:
I need to convert the code in http://support.microsoft.com/?kbid=240653 to VB.net Does anybody know what should be done? Thanks. Ian
2
by: sindhu80 | last post by:
Hi, Can somebody help me to convert the following code to c# function uploadToImageshack($filename) { $ch = curl_init("http://www.imageshack.us/index.php"); ...
1
by: omy2k | last post by:
I have been trying to convert this code to visual C#. can nyone help? #include <stdio.h> #include <time.h> clock_t start = clock(); /* Code you want timed here */ printf("Time elapsed: %f\n",...
1
by: krishnaneeraja | last post by:
Hi, im developing a web application.In that i want search engine code.but i have that code in PHP.so plz help me how to convert PHP code to C# code. Giv me any reply. Thanks & Regards,...
9
by: aliusman | last post by:
Hi Every one, I have a perl script which uses the following code to decode the username saved in a cookie. I want to parse that cookie in php for adding some more features in the application. The...
12
by: dorandoran | last post by:
I followed this link to add new record from gridview. So far it's good but I need to modify the last piece to edit the record that I will supply the record id. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.