473,385 Members | 1,344 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.

SQL In VBA getting Compile Error: Expected Case

171 100+
Hi Everyone,
I keep on getting an error saying Compile Error: Expected Case in my (MS Access) VBA What I was trying to do was to do a DSUM function for a Table where the criteria was coming from another table, I later found the criteria needs to be from within the domain table I had set DSUM function (makes sense). I then when to Query Bulder to Build The SQL string as Below and put it in VBA
Expand|Select|Wrap|Line Numbers
  1. Private Sub tbTotalColl_AfterUpdate()
  2.  'This should get the Sum of All the tblCollections.Amt figures grouped by  
  3.  'tblJobDetails.TFN, tblJobDetails.RcptID is the 1 side & tblCollections.RcptID 
  4.  'is the MANY side of the tables relationship 
  5.     SELECT tblJobDetails.TFN, Sum tblCollections.Amt AS SumOfAmt _
  6.     & FROM tblJobDetails INNER JOIN tblCollections ON tblJobDetails.RcptID =               
  7.     tblCollections.RcptID _
  8.     & GROUP BY tblJobDetails.TFN _
  9.     & HAVING tblJobDetails.TFN = frmPinkCardsMAIN.cboFullName Or    
  10.     tblJobDetails.TFN
  11.  
  12. End Sub
Thanks
Apr 8 '07 #1
5 15155
iburyak
1,017 Expert 512MB
Try this:


[PHP]SELECT tblJobDetails.TFN, Sum(tblCollections.Amt) AS SumOfAmt _
& FROM tblJobDetails INNER JOIN tblCollections ON tblJobDetails.RcptID = tblCollections.RcptID _
& WHERE tblJobDetails.TFN = frmPinkCardsMAIN.cboFullName _
& GROUP BY tblJobDetails.TFN [/PHP]


Hope it helps.
Apr 8 '07 #2
Killer42
8,435 Expert 8TB
The problem is nothing to do with the SQL syntax. It is the fact that you have simply typed SQL into your VBA module. You can't do that.

Your VBA code will need to place that SQL statement in a string, and then execute it in some way. Or place it in the appropriate property to have the desired effect - perhaps a form's Filter or RecordSource property, or some such.

The error you are receiving indicates that your VBA "Select Case" statement is not correctly written. And since it isn't VBA code, this is hardly surprising.

P.S. I have no idea whether the SQL syntax is correct or not - that's another story.
Apr 9 '07 #3
iburyak
1,017 Expert 512MB
The problem is nothing to do with the SQL syntax. It is the fact that you have simply typed SQL into your VBA module. You can't do that.

Your VBA code will need to place that SQL statement in a string, and then execute it in some way. Or place it in the appropriate property to have the desired effect - perhaps a form's Filter or RecordSource property, or some such.

The error you are receiving indicates that your VBA "Select Case" statement is not correctly written. And since it isn't VBA code, this is hardly surprising.

P.S. I have no idea whether the SQL syntax is correct or not - that's another story.
Syntax didn't look correct to me.
Apr 9 '07 #4
Killer42
8,435 Expert 8TB
Syntax didn't look correct to me.
You could be right. I didn't actually read the SQL - I just glanced at it and saw the VBA/SQL problem, so didn't bother to read further. (In fact, I was already expecting it, and just confirmed my suspicions).
Apr 9 '07 #5
iburyak
1,017 Expert 512MB
You are great.... :)
Apr 9 '07 #6

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

Similar topics

6
by: Erik H. | last post by:
Trying to connect to MySQL db on localhost, and populate datagrid from a dataset using code inline method. Getting the following compile error: Error Message: "CS0246: The type or namespace...
3
by: wwwursa | last post by:
I am trying to use the Right function in a VB6 program. I have used it used many times before in other programs. When I press the enter key after entering the code line, the word "Right" turns...
1
by: darrel | last post by:
Hello, i need you help, can someone whats the cause of getting an error of Expected function or variable, its like this i have a function code in a module and call it on my main form.. here my code:...
1
by: kieran04 | last post by:
every time i run this program in VBE i keep getting the message 'Compile Error: expected array' for the two bold lines underneath, please help? Public Function KnotsToKmPerHr(knots As...
2
by: rocky102 | last post by:
I am a novice old timer who enjoys fooling around with excel, I copied this macro from and old computer and wanted to use it one a new one I got. Its supposed to draw a line across a row when...
0
by: ppletkov | last post by:
Hi - I apologize if this is a simple question in advance :-) (hopefully it is so its quickly resolved!) i'm trying to figure out why i keep getting an error (Compile Error : expected function or...
1
by: Dorota Prywata | last post by:
Hi, I need help with VBA Macro for Auto-filter to high lite a header plp advice as per below course a I got Compile error: Expected End Sub ? Sub Macro1() Function FilterOn(myCell As Range)...
2
by: engrlorie | last post by:
I am a newbie in programing and is currently designing a program using VB6 with access 03 database. Unfortunately, I am stuck with the error. Please help me.. can't decipher the problem myself....
4
by: Lindsay Bradley | last post by:
I have code built into a form in Access and everytime I try to open the form it gives me a Compile error: Expected array message and then highlights the word Left. I did not create this program and...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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:
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
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.