473,666 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL In VBA getting Compile Error: Expected Case

171 New Member
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 15177
iburyak
1,017 Recognized Expert Top Contributor
Try this:


[PHP]SELECT tblJobDetails.T FN, Sum(tblCollecti ons.Amt) AS SumOfAmt _
& FROM tblJobDetails INNER JOIN tblCollections ON tblJobDetails.R cptID = tblCollections. RcptID _
& WHERE tblJobDetails.T FN = frmPinkCardsMAI N.cboFullName _
& GROUP BY tblJobDetails.T FN [/PHP]


Hope it helps.
Apr 8 '07 #2
Killer42
8,435 Recognized Expert Expert
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 Recognized Expert Top Contributor
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 Recognized Expert Expert
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 Recognized Expert Top Contributor
You are great.... :)
Apr 9 '07 #6

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

Similar topics

6
3184
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 name 'CoreLab' could not be found (are you missing a using directive or an assembly reference?)" I downloaded the add on for connecting to MySQL using ADO.NET and installed it, but am still getting this error. Anybody ever run into this before?
3
5419
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 into "RIGHT" in all capital letters The line is LongText = RIGHT(LongText, 2) I have used Option Explicit to make sure all variables are correct. When I run the entire program I get an the following error message "Compile error Expected...
1
9005
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: Function DTR7() Dim rs As New ADODB.Recordset Dim cnn As New ADODB.Connection Dim x As Integer frmMain.Command2.Visible = True frmMain.Command1.Visible = False
1
5145
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 Double) As Double Dim Km As Double KNOTS_TO_KM = 1.852 Km = knots * KNOTS_TO_KM KnotsToKmPerHr = Km
2
16420
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 there is a change from one number to another. When I try to use it I get this error Compile Error Expected End Sub Help please.
0
1512
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 variable) for my .find method. I have checked the format of this statement and it appears correct...? Dim ItemNumberWLO As String Dim ItemNumberWLN As String While Not WLO.EOF
1
15115
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) As Boolean On Error Resume Next With myCell.Parent.AutoFilter With .Filters(myCell.Column - .Range.Column + 1)
2
6556
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. Scenario is I have 4 tables (lightinfo, location, characteristics, and pics). They are connected through National ID from lightinfo. strQuery = "SELECT LIGHTINFO.info_NationalNo, LIGHTINFO.info_InternationalNo, LIGHTINFO.info_namriaName, " & _...
4
8455
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 know very little about VBA but have been given the responsibility to take over this program. Please help I'm desperate! Private Sub Form_Open(Cancel As Integer) 'Added 'unlock fields for STL If TempVars! And Status <> "Closed" And Status...
0
8363
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8883
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8645
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6203
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4200
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.