Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Type mismatch:'alert' vbscript to compact access db

Reply
 
Old 04-16-2009   #1 (permalink)
Janis


 
 

Type mismatch:'alert' vbscript to compact access db

I added an alert dialog to this script at the end to let the user know the
Access database got compacted successfully. Now I get the error:"type
mismatch:'alert' VBscript runtime error so something is wrong with my alert
dialog box. Thanks,
-----
Dim objScript
Dim objAccess
Dim strPathToMDB
Dim strMsg

' ///////////// NOTE: User must edit variables in this section /////
'
' The following line of code is the only variable that need be edited
' You must provide a path to the Access MDB which will be compacted
'
strPathToMDB = "Z:\acsc_be.mdb"
'
' ////////////////////////////////////////////////////////////////

' Set a name and path for a temporary mdb file
strTempDB = "C:\Comp0001.mdb"

' Create Access 97 Application Object
'Set objAccess = CreateObject("Access.Application.8")

' For Access 2000, use Application.9
Set objAccess = CreateObject("Access.Application.11")

' Perform the DB Compact into the temp mdb file
' (If there is a problem, then the original mdb is preserved)
objAccess.DBEngine.CompactDatabase strPathToMDB, strTempDB

If Err.Number > 0 Then
' There was an error. Inform the user and halt execution
strMsg = "The following error was encountered while compacting
database:"
strMsg = strMsg & vbCrLf & vbCrLf & Err.Description
Else
' Create File System Object to handle file manipulations
Set objScript = CreateObject("Scripting.FileSystemObject")

' Back up the original file as Filename.mdbz. In case of undetermined
' error, it can be recovered by simply removing the terminating "z".
objScript.CopyFile strPathToMDB, strPathToMDB & "z", True

' Copy the compacted mdb by into the original file name
objScript.CopyFile strTempDB, strPathToMDB, True

' We are finished with TempDB. Kill it.
objScript.DeleteFile strTempDB
alert("compact successful")
End If

' Always remember to clean up after yourself
Set objAccess = Nothi

My System SpecsSystem Spec
Old 04-16-2009   #2 (permalink)
ekkehard.horner


 
 

Re: Type mismatch:'alert' vbscript to compact access db

Janis schrieb:
Quote:

> I added an alert dialog to this script at the end to let the user know the
> Access database got compacted successfully. Now I get the error:"type
> mismatch:'alert' VBscript runtime error so something is wrong with my alert
> dialog box. Thanks,
[...]
The VBScript way to send a message is

MsgBox "<message>"

(additional parameters possible; see the Docs); use this instead of
the javascriptive alert().
Quote:

> -----
> Dim objScript
> Dim objAccess
> Dim strPathToMDB
> Dim strMsg
>
> ' ///////////// NOTE: User must edit variables in this section /////
> '
> ' The following line of code is the only variable that need be edited
> ' You must provide a path to the Access MDB which will be compacted
> '
> strPathToMDB = "Z:\acsc_be.mdb"
> '
> ' ////////////////////////////////////////////////////////////////
>
> ' Set a name and path for a temporary mdb file
> strTempDB = "C:\Comp0001.mdb"
>
> ' Create Access 97 Application Object
> 'Set objAccess = CreateObject("Access.Application.8")
>
> ' For Access 2000, use Application.9
> Set objAccess = CreateObject("Access.Application.11")
>
> ' Perform the DB Compact into the temp mdb file
> ' (If there is a problem, then the original mdb is preserved)
> objAccess.DBEngine.CompactDatabase strPathToMDB, strTempDB
>
> If Err.Number > 0 Then
> ' There was an error. Inform the user and halt execution
> strMsg = "The following error was encountered while compacting
> database:"
> strMsg = strMsg & vbCrLf & vbCrLf & Err.Description
> Else
> ' Create File System Object to handle file manipulations
> Set objScript = CreateObject("Scripting.FileSystemObject")
>
> ' Back up the original file as Filename.mdbz. In case of undetermined
> ' error, it can be recovered by simply removing the terminating "z".
> objScript.CopyFile strPathToMDB, strPathToMDB & "z", True
>
> ' Copy the compacted mdb by into the original file name
> objScript.CopyFile strTempDB, strPathToMDB, True
>
> ' We are finished with TempDB. Kill it.
> objScript.DeleteFile strTempDB
> alert("compact successful")
> End If
>
> ' Always remember to clean up after yourself
> Set objAccess = Nothi
My System SpecsSystem Spec
Old 04-16-2009   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: Type mismatch:'alert' vbscript to compact access db

Janis wrote:
Quote:

>I added an alert dialog to this script at the end to let the user know the
> Access database got compacted successfully. Now I get the error:"type
> mismatch:'alert' VBscript runtime error so something is wrong with my
> alert
> dialog box. Thanks,
> -----
> Dim objScript
> Dim objAccess
> Dim strPathToMDB
> Dim strMsg
>
> ' ///////////// NOTE: User must edit variables in this section /////
> '
> ' The following line of code is the only variable that need be edited
> ' You must provide a path to the Access MDB which will be compacted
> '
> strPathToMDB = "Z:\acsc_be.mdb"
> '
> ' ////////////////////////////////////////////////////////////////
>
> ' Set a name and path for a temporary mdb file
> strTempDB = "C:\Comp0001.mdb"
>
> ' Create Access 97 Application Object
> 'Set objAccess = CreateObject("Access.Application.8")
>
> ' For Access 2000, use Application.9
> Set objAccess = CreateObject("Access.Application.11")
>
> ' Perform the DB Compact into the temp mdb file
> ' (If there is a problem, then the original mdb is preserved)
> objAccess.DBEngine.CompactDatabase strPathToMDB, strTempDB
>
> If Err.Number > 0 Then
> ' There was an error. Inform the user and halt execution
> strMsg = "The following error was encountered while compacting
> database:"
> strMsg = strMsg & vbCrLf & vbCrLf & Err.Description
> Else
> ' Create File System Object to handle file manipulations
> Set objScript = CreateObject("Scripting.FileSystemObject")
>
> ' Back up the original file as Filename.mdbz. In case of
> undetermined
> ' error, it can be recovered by simply removing the terminating
> "z".
> objScript.CopyFile strPathToMDB, strPathToMDB & "z", True
>
> ' Copy the compacted mdb by into the original file name
> objScript.CopyFile strTempDB, strPathToMDB, True
>
> ' We are finished with TempDB. Kill it.
> objScript.DeleteFile strTempDB
> alert("compact successful")
> End If
>
> ' Always remember to clean up after yourself
> Set objAccess = Nothi
There is no method called Alert, unless you create one and add it to your
script.. I suggest instead you use:

Call MsgBox("compact successful")

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Type mismatch: FormatNumber VB Script
Date Type mismatch in criteria expression VB Script
Data type mismatch in criteria expression (with Request.form) VB Script
Data type mismatch in criteria expression VB Script
HTA: type mismatch (runtime) on sub call in OnChange VB Script


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46