Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
'''' Define the file full name.
strDBFullName = "C:\Users\Charles\Documents\Weather\Weather.accdb"

'''' Check whether the file exists.
If Not CreateObject("Scripting.FileSystemObject").FileExists(strDBFullName) Then
  MsgBox "File """ & strDBFullName & """ does not exist or is not available.", vbCritical, "File Not Found"
  WScript.Quit
End If

'''' Create a new Access-instance, display it and open the file.
Set oAC = CreateObject("Access.Application")
oAC.Visible = True
Set oDB = oAC.OpenCurrentDataBase strDBFullName

'	oDB.Run "Update"

'''' Opens and Runs The Auto open Macro

'''' Save the workbook and clean up.
oDB.Save
oDB.Close
oAC.Quit
Set oAC = Nothing


What I have tried:

I have tried fully retyping the code line, and entering the the file path and name in quotes and parentheses. All the on line information I have found seems to suggest that this code is valid
Posted
Updated 25-Oct-17 8:38am

1 solution

Line 13, character 35 is:
Set oDB = oAC.OpenCurrentDataBase strDBFullName
----------------------------------^

You almost certainly need to enclose the parameter in parentheses:
Set oDB = oAC.OpenCurrentDataBase(strDBFullName)
 
Share this answer
 
Comments
Member 13485326 25-Oct-17 15:43pm    
If I do that it does load the database but get another error line 13 Chr 1, Object required; 'oAC.opencurrentdatabase(...)'
Dave Kreskowiak 25-Oct-17 16:33pm    
Remove the "Set oDB =" part. The function "OpenCurrentDatabase" doesn't return anything.
Member 13485326 26-Oct-17 0:51am    
Thanks that resolves the issue on line 13. However i now get an error for line 20, chr 1, object required: oDB
Richard Deeming 26-Oct-17 7:31am    
Because that's not how the Access object model works. OpenCurrentDatabase doesn't return an object, so oDB is not set to an object.

You need to review how Access works, and correct your script:
Access VBA reference[^]
Member 13485326 26-Oct-17 11:26am    
I think I now have the script working, (It runs manually OK) so I'll set up the SChedule to run it tonight and check the result tomorrow. The Code is shown below:

'''' Define the file full name.
strDBFullName = "C:\Users\Charles\Documents\Weather\Weather.accdb"

'''' Check whether the file exists.
If Not CreateObject("Scripting.FileSystemObject").FileExists(strDBFullName) Then
MsgBox "File """ & strDBFullName & """ does not exist or is not available.", vbCritical, "File Not Found"
WScript.Quit
End If

'''' Create a new Access-instance, display it and open the file.
Set oAC = CreateObject("Access.Application")
oAC.Visible = True
oDB = oAC.OpenCurrentDataBase(strDBFullName)
oAC.UserControl = True

'''' Opens and Runs The Update Macro
oDB = oAC.DoCmd.RunMacro("Update", , "")


'''' Save the workbook and clean up.

CloseDB = oAC.CloseCurrentDatabase
CloseAP = oAC.Application.Quit
Set oAC = Nothing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900