I am trying to insert some records into MS Access Table with the help of below VB Script. But when am trying to execute it, it’s throwing Compilation error: Expected end of statement. Could someone please help me figure out where am I going wrong.
Private Sub Form_Click()
Dim dbs As DAO.Database
Dim DbFullNAme As String
DbFullName = "D:GDiamondFINAL MS-AccessMS-Access project.accdb"
Set dbs = OpenDatabase(DbFullName)
dbs.Execute "INSERT INTO [2014_Status] ( Prompt, Project_Name, STATUS,Release_Name )SELECT RoadMap.SPRF_CC, RoadMap.SPRF_Name, RoadMap.Project_Phase,RoadMap.Release_Name FROM RoadMap WHERE (((Exists (select 1 FROM [2014_Status] where RoadMap.SPRF_CC = [2014_Status].[Prompt]))=False));"
dbs.Close
End Sub
Pankaj Jaju
5,2812 gold badges25 silver badges41 bronze badges
asked Apr 23, 2014 at 17:14
6
VBScript (as opposed to VBA or other dialects) does not support typed Dims. So
Dim dbs As DAO.Database
Dim DbFullNAme As String
need to be
Dim dbs
Dim DbFullNAme
VBscript has no native OpenDatabase() function. You need to use ADO to connect to your Access ‘database’. First create a connection
Set dbs = CreateObject("ADODB.Connection")
Then determine the connection string and
dbs.Open cs
The rest of your code should work.
Update wrt comment:
The error message:
D:GDiamondFINAL MS-Accessquery1.vbs(2, 9) Microsoft VBScript compilation error: Expected end of statement
prooves that the OT tried to write a VBScript (the addition of the misleading vba/access tags is (C) Pankaj Jaju).
answered Apr 23, 2014 at 17:29
Ekkehard.HornerEkkehard.Horner
38.3k2 gold badges44 silver badges94 bronze badges
3
So lets break down the real reason why this code doesn’t work.
You copied and pasted Visual Basic for Applications(VBA) into a .VBS(Visual Basic Script) file and expected it to work, I assume.
The problem with this is that VBA and VBScript are slightly different languages. Review the info section for both tags on stackoverflow when you get the opportunity.
For now lets just patch your code and maintain your DAO object so you don’t have to reconstruct your Database usage with ADODB.
ExecuteInsert
Sub ExecuteInsert()
Dim dbs, DbFullName, acc
Set acc = createobject("Access.Application")
DbFullName = "D:GDiamondFINAL MS-AccessMS-Access project.accdb"
Set dbs = acc.DBEngine.OpenDatabase(DbFullName, False, False)
dbs.Execute "INSERT INTO [2014_Status] ( Prompt, Project_Name, STATUS,Release_Name )SELECT RoadMap.SPRF_CC, RoadMap.SPRF_Name, RoadMap.Project_Phase,RoadMap.Release_Name FROM RoadMap WHERE (((Exists (select 1 FROM [2014_Status] where RoadMap.SPRF_CC = [2014_Status].[Prompt]))=False));"
dbs.Close
msgbox "done"
End Sub
Changes made.
- Blocked your dim’d variables and removed
As ***
statements for vbscript compatibility - Set an access object so you could maintain the remainder of your code.
- Added the
acc.DBEngine.
beforeOpenDatabase
with additional parameters. - Renamed your Sub from
Form_Click
to ExecuteInsert, then placedExecuteInsert
at the top of the code so that the vbscript activates the sub. If you just place a sub in a vbscript file, it will not necessarily run, you have to activate it directly.
This code is tested and functions. Best of luck to you.
answered Apr 23, 2014 at 19:20
RichRich
4,0843 gold badges26 silver badges44 bronze badges
1
Adding to Ekkehard.Horner
http://www.csidata.com/custserv/onlinehelp/vbsdocs/vbs6.htm
VBScript has only one data type called a Variant. A Variant is a
special kind of data type that can contain different kinds of
information, depending on how it’s used. Because Variant is the only
data type in VBScript, it’s also the data type returned by all
functions in VBScript.
answered Apr 23, 2014 at 17:32
0
Troubleshooting Code 800A0401 – Expected End of Statement
Good news, here is another example of a WSH error message with a helpful Char: number. Count along the line until you get to the offending character. With Error 800A0401 start by looking for missing ampersands (&).
Introduction to Code 800A0401
Error code, 800A0401 occurs when you execute a VBScript. This is a compilation error, therefore check your punctuation. A wild guess, you have left out an ampersand (&), or possibly a comma.
The Symptoms You Get
The script does not execute as you had hoped. Instead, Windows Scripting host generates a message box like this picture: Good news, I have three examples of code: 800A0401.
The Cause of Code 800A0401 VBScript Error
Your VBScript contains a punctuation error. Note: The clue from Source: Microsoft VBScript compilation error, this means a syntax error in your script. In this case the Char: number (33) is particularly valuable in troubleshooting.
The Solution to Error: Expected end of statement
Check the syntax of your script, in particular double-check punctuation marks (&, comma, speech marks or full stop.). In this instance, Windows Scripting Host has detected a mix-up between a comma and a full stop. As ever, a line number is helpful when troubleshooting, moreover, any Char : number other than 1, will pin-point the problem.
‡
Example 1 of Script for Code 800A0401
Note: The error is at Line 3, Character 33 – wbemServices, Instances
It should be wbemServices.Instances (Full stop, and not a comma)
‘ VBScript Error 800A0401
strComputer = «Alan»
set wbemservices = GetObject(«Winmgmts:\» & strComputer)
set wbemObjectSet = wbemServices, InstancesOf («win32_LogicalMemoryConfiguration»)
For each wbemobject in wbemobjectset
WScript.echo «Tot Physical Memory » & wbemobject.totalPhysicalMemory
Next
Guy Recommends: A Free Trial of the Network Performance Monitor (NPM) v11.5
SolarWinds’ Orion performance monitor will help you discover what’s happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
Download a free trial of Solarwinds’ Network Performance Monitor
Example 2 of Script for Error 800A0401
Problem
Wscript.Echo objNetwork.UserName » at » & objNetwork.ComputerName
An & (ampersand) is missing it should be:
Correction
Wscript.Echo objNetwork.UserName & » at » & objNetwork.ComputerName
‘ VBScript 800A0401 Error
Set ObjNetwork = CreateObject(«Wscript.Network»)
Wscript.Echo objNetwork.UserName » at » & objNetwork.ComputerName
[ThemesGuy/google_leader728htm]
Example 3 – Missing Comma
The error is on line 10 char 33, it needs a comma between the drive letter and the UNC path
objNetwork.MapNetworkDrive «R:» «\alanbackup»
objNetwork.MapNetworkDrive «R:» , «\alanbackup»
‘ BudgetPear.vbs
‘ Script to map the Budget share on the server pear
‘ Version 1.1 August 2010
‘ Guy Thomas https://computerperformance.co.uk
Option Explicit
Dim objNetwork
Set objNetwork = CreateObject(«Wscript.Network»)
objNetwork.MapNetworkDrive «R:» «\alanbackup»
WSript.echo » Share Mapped «
WScript.Quit
‘ End of Guy’s script
Summary of Error Code 800A0401
As usual with 0800 error codes, check the line number and the char number. Pay careful attention to any punctuation. Is there a comma, missing? Could there be a comma, where the script needs a full stop?
See More Windows Update Error Codes 8004 Series
• Error 800A101A8 Object Required •Error 800A0046 •Error 800A10AD •Error 800A000D
• Error 80048820 •Error 800A0401 •Review of SolarWinds Permissions Monitor
• Error 80040E14 • Error 800A03EA • Error 800A0408 • Error 800A03EE
Guy Recommends: WMI Monitor and It’s Free!
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems. Fortunately, SolarWinds have created the WMI Monitor so that you can examine these gems of performance information for free. Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.
Download your free copy of WMI Monitor
Do you need additional help?
- For interpreting the WSH messages check Diagnose 800 errors.
- For general advice try my 7 Troubleshooting techniques.
- See master list of 0800 errors.
- Codes beginning 08004…
- Codes beginning 08005…
- Codes beginning 08007…
- Codes beginning 0800A…
Give something back?
Would you like to help others? If you have a good example of this error, then please email me, I will publish it with a credit to you:
If you like this page then please share it with your friends
|
|
- Remove From My Forums
-
Question
-
I cannot figure out what is wrong here.. I’m running this on a .asp page and it seems to work when inserting into a MS Access database but cant into MS SQL database..
Error is at line starting with «RsContactForm.Open INSERT INTO» and the error displayed is:
Microsoft VBScript compilation error ‘800a0401’
Expected end of statement
Sub DB sConnStr = "Provider=sqloledb;Data Source=******.db.1and1.com,1433;Initial Catalog=******;User Id=*******;Password=*********;" Set OBJdbConn = Server.CreateObject("ADODB.Connection") OBJdbConn.Open sConnStr Set RsContactForm = Server.CreateObject("ADODB.recordset") RsContactForm.Open "INSERT INTO tbl_Projects(ProjName,ProjContact,ProjAddress,ProjCity,ProjState,ProjZip,ProjPhone,ProjStyle,ProjLeadTime,ProjDesc,ProjCategory,ProjEmail,ProjPrivate,projlastuser,projrand) VALUES ('" & Request.Form("T0") & "''" "''" & Request.Form("T1") & "''" "''" & Request.Form("T3") & "''" "''" & Request.Form("T4") & "''" "''" & Request.Form("T0") & "','" & Request.Form("T1") & "','" & Request.Form("T2") & "','" & Request.Form("T3") & "','" & Request.Form("T4") & "','" & Request.Form("T5") & "','" & Request.Form("T6") & "','" & Request.Form("T8") & "','" & Request.Form("T9") & "','" & Request.Form("T10") & "','2','" & Request.Form("T7") & "','""','" & stampedname & "','" & randgen() & "');", OBJCONN
RsContactForm.Close Set RsContactForm = Nothing OBJdbConn.Close Set OBJdbConn = Nothing end sub
Any help is greatly appreciated…
-
Edited by
Sunday, February 9, 2014 9:02 PM
Remove database connections
-
Edited by
Answers
-
I understand that you can figure it out, because the code is unreadable. Try:
cmd.CommandText = «INSERT INTO tbl_Projects(» & _
«ProjName, ProjContact, ProjAddress, ProjCity, ProjState, » &_
«ProjZip, ProjPhone, ProjStyle, ProjLeadTime, ProjDesc, » & _
«ProjCategory, ProjEmail, ProjPrivate, projlastuser, projrand) » & _
» VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); «
cmd.Parameters.Append cmd.CreateParameter(«@ProjName», adVarWChar, 40, Request.Form(«T0»)
cmd.Parameters.Append cmd.CreateParameter(«@ProjContact», adVarWChar, 40, Request.Form(«T1»)
…There are a number of reasons you should use parameterised commands:
1) Improves readability of your code.
2) More efficient use of the plan cache in SQL Server.
3) Removes the risk for SQL injection.
4) No hassle with date formats.Note: the 40 in the example is a dummy number. You should put the actual number of the target column here. You will need to change the enum value for the type for columns that are not nvarchar.
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
-
Proposed as answer by
pituachMVP
Sunday, February 9, 2014 9:57 PM -
Marked as answer by
Fanny Liu
Friday, February 28, 2014 11:08 AM
-
Proposed as answer by
Introduction
Every programming language has its own grammar and vocabulary — technically known as syntax. Having a mastery of any language implies that you have a sound knowledge of its syntax.
As a beginner in VBA, you might be confronted with frustrating errors like the “Expected: end of statement” error. Be rest assured, no matter how experienced you’re with VBA coding, errors are always going to be a part of it.
The difference between a novice and an expert VBA programmer is that the expert programmers know how to effectively handle and use errors. This article will help you better understand the error above.
Types of errors in VBA
There are three types of errors in VBA: syntax errors, compile errors, and runtime errors.
Syntax Error
A syntax error, as you can guess from the name, occurs when VBA finds something wrong with the syntax in your code. When you type a line of code, VBA checks if the syntax is correct.
As soon as you hit enter, if VBA finds that something is missing in the syntax, it instantly shows a message with some text that can help you understand the missing part, as you can see in the screenshot below:
Note: You need to enable the ‘Auto Syntax Check’ in the VBA option for the error dialog box to appear when there is an error. If not, VBA will only highlight the line without showing the error dialog box. The gif below shows you how to enable the error dialog box in VBA.
Compile Error
Compile errors occur when something is missing that is needed for the code to run. For example, in the code below, as soon as you run the code, it will show an error.
Note the difference between the syntax error and the compile error. The syntax error occurs even before you run the code and the font of the problematic line turns to red. The compile error occurs when you try to run the code and VBA identifies that something is missing.
Run Time Errors
Runtime errors are those that occur when the code is running. Run time errors will occur only when all the syntax and compile errors have been taken care of. They are not due to errors in the code itself, but rather due to factors external to the code — like a wrong input by the user, or an object that is not existing.
For example, if you run code that is supposed to activate an Excel worksheet, but that worksheet is unavailable (either deleted or its name changed), your code would give you a runtime error.
Unlike with the two previous errors, when a runtime error occurs, the message in the Run-time error dialog box is a little more explicit because it explains the problem and that can help you correct it.
Coming back to our specific error (“Expected: end of statement”), let’s write and run some code that will generate the error.
Step 1: Open the Visual Basic Editor and create a new module as seen in the gif below.
Step 2: Write or copy and paste the following code:
Sub GenerateError() Dim i As Integer = 5 End Sub
Before you even run the code, you will have the following result:
The error comes from the fact that two statements have been written in one line instead of two. The code should be:
Line 1: Dim i As Integer
Line 2: i = 5
Possible reasons for the “Expected: end of statement” error
From the types of errors in VBA described above, you must have guessed that the “Expected: end of statement” error is a syntax error. As such, the possible reasons for the error are as varied as the number of mistakes that you can make while writing a line of code.
Without being exhaustive, below is a list of possible reasons for that error:
1) Writing two statements in one line (see the example above)
How to fix: Check to see if two different statements have inadvertently been put on the same line then send the second statement to a new line.
2) Absence of parentheses
How to fix: Make sure you have parentheses (both open and close) where necessary.
3) Absence of white space
How to fix: Any identifier that is immediately followed by a &
, like name&
and affiliation&
, is interpreted as a Long variable, so the lack of whitespace in front of the concatenation operator (&) is causing a parse error. To solve the problem, you just need to put a space between the variables and the concatenation operator. Instead of writing name&
, write name &
.
Speed up your PC in just a few clicks
Download this software now and say goodbye to your computer problems.
Over the past few weeks, some users have encountered Microsoft Vbscript compilation error 800a0400. This problem can arise for several reasons. We’ll cover them below. Error 800A0400 is a common target when running VBScript. Crazy guess, you were missing out on the fact that you are just ordering at the head of this queue.
Error Fix Code 800A0400 – Statement Awaiting
Perhaps, instead of “Pending statement”, “missing character” would be a perfect error message for every line mentioned in the evaluation error message.
An Introduction To The 800A0400 Code
Standard error 800A0400 is a common message when implementing VBScript. The wild claim that you missed the command at the beginning of the line.
Explain Symptoms Clearly
The script will not work as expected. Instead, you are a system of exchange withmessages like this picture:
Cause Of Error 800A0400
Take out data type terms and you remove the obstacle – one way or another. Another issue with this script is that the house will look like it handles a button click (Private Sub Command1_Click); If this is a VB script, and not VB 6, then the button to view the manager is not needed.
Your VBScript contains outdated instructions. This is a confusing observation disadvantage. The good news, however, is that I have three examples. Most likely, you have posted the instruction for exactly this. the logic is not perfect in the scenario you are considering. For example, higher parentheses or a missing command.
Note: Notice “Source: Microsoft VBScript Compilation Error”. The point is that “compilation error”, and not just “runtime error”, literally means that it is a syntax error in your script.
Solution As Error: Statement Expected
The Windows Script Host gives us two helpful hints: evaluate it, look at line: 10, don’t count or think about blank lines. The second is char: a set of 1 is useful for tracking down an error. In some cases, there is something wrong with the choice of instructions.
Number, line, as sometimes happens, are crucial for identifying this error. The problem is that this whole series is gibberish for the VBScript engine, although you are most likely found out.Make a simple mistake.
Example Of Error Code: 800A0400
– WSHname.Sample vbs
– VBScript to check the WSH version
– By Guy Thomas https://computerperformance.co.uk/
– Version 2.3 September – “2010
… – – – – – – – – – – – – – – – – – – – – – – – – – ”––––––-
Continue on error Next
WScript. Echo” WSH “-Version: & WScript.Version & “&” WScript.BuildVersion
& vbcr “File and name:” WScript.ScriptName
WScript.Quit
WScript.Echo “WSH” version: & WScript.Version & “” &
â € ˜ _ WSHname.Sample vbs
â € VBScript to evaluate the WSH version
â € • By Guy Thomas https://computerperformance.co.uk/
â € • Version 2.3 September – 2010
…………………… € ”––––––-
Error recovery Next
WScript.Echo” WSH ins version: & WScript.Version & “Zoll & _ WScript .BuildVersion
& vbcr “File and name:” WScript.ScriptName
WScript.Quit
Guy Recommends: Network Performance Monitor (NPM) Free Trial V11.5
SolarWinds’ Orion Performance Monitor helps you understand what’s going on on your network. A utility that will also help you with troubleshooting; The dashboard is sure to show if the root cause is a bad link, faulty devices, or possibly resource overload. me
Moreover, NPM offers solutions to computer network problems. It also has the ability to monitor the health of custom VMware virtual machines. I recommend the public give NPM a try now.
Example 2 Of All 800A0400
Speed up your PC in just a few clicks
Is your computer running slow and unstable? Are you plagued by mysterious errors, and worried about data loss or hardware failure? Then you need ASR Pro � the ultimate software for repairing Windows problems. With ASR Pro, you can fix a wide range of issues in just a few clicks, including the dreaded Blue Screen of Death. The application also detects crashing applications and files, so you can quickly resolve their problems. And best of all, it�s completely free! So don�t wait � download ASR Pro now and enjoy a smooth, stable and error-free PC experience.
Speaking of stupid mistakes, just … the apostrophe in Out removes those dashes. Script
… this is below, and our pclist.txt contains only 2 lines:
… mainrv
… computer1
…… € “- – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Const ForReading = 1
Define objDictionary CreateObject (“Scripting = .Dictionary”)
Define objFSO = CreateObject (“Scripting. FileSystemObject “)
Set objTextFile to objFSO.OpenTextFile _
(” e: scripts pclist.txt “, ForReading)
i = 0
Do before objTextFile.AtEndOfStream
strNextLine = objTextFile. Readline
objDictionary.Add i, strNextLine
i equals i + 1
Loop
For each object here in = objDictionary
StrComputer objDictionary.Item (objItem)
Set objWMIService = GetObject ( “winmgmts:” “impersonationLevel = impersonate! ” _
& & strComputer & ” root cimv2″)
Set colServices implies objWMIService.ExecQuery _
(“SELECT * FROM Win32_Service”)
Wscript.Echo strComputer, colServices.Count
Next
Example 3 From 800A0400 (alternate Code = “Engineer Available”)
Guy SolarWinds Recommends: Engineer’sToolset V10
This v10 Engineer Toolkit contains a complete console as well as 50 troubleshooting utilities p. C. Problems. Guy says it helps my home keep track of what’s happening on the web, in addition to tools that teach me more about how the underlying system works.
There can be so many good devices; it’s no different than letting a candy store run wild. Fortunately, the utilities make sense: visual monitoring, network discovery, diagnostics, and Cisco tools. Test the SolarWinds Engineer Toolkit Now!
Download a fully functional trial identical to Engineer’s Toolset v10
New Example – End If Not Required
The 800A0400 error message in VBScript is displayed whenever the user offers an “end” statement when it just isn’t needed. For example, in this scenario, the user specifies “End If” if there is no “If” statement to exit.
MsgBox “Click OK to continue”
Input = InputBox (“Please enter your name”)
End If
There was no need to define End if ”for the user, so the script host confirms that the user should define this“ If ”statement, but that wouldn’t make more sense. “Did he alert the user to remove all End If statements?
Download this software now and say goodbye to your computer problems.
Erro De Compilacao Do Microsoft Vbscript 800a0400
Microsoft Vbscript Compilatiefout 800a0400
Blad Kompilacji Microsoft Vbscript 800a0400
Microsoft Vbscript Kompileringsfel 800a0400
Microsoft Vbscript Kompilierungsfehler 800a0400
Errore Di Compilazione Vbscript Microsoft 800a0400
Microsoft Vbscript 컴파일 오류 800a0400
Oshibka Kompilyacii Microsoft Vbscript 800a0400
Error De Compilacion Microsoft Vbscript 800a0400
Erreur De Compilation Microsoft Vbscript 800a0400