Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft VBScript compilation error: Expected end of statement

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:\G\Diamond\FINAL MS-Access\MS-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
like image 808
user2412576 Avatar asked Oct 16 '25 17:10

user2412576


1 Answers

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:\G\Diamond\FINAL MS-Access\query1.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).

like image 52
Ekkehard.Horner Avatar answered Oct 19 '25 07:10

Ekkehard.Horner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!