![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 script.. I suggest instead you use: Call MsgBox("compact successful") -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
![]() |
| 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 | |||