wrong number of arguments

G

Guest

i am developing an application for a client, using access 97. i have placed a compact data base button on the main menu of the application. the user is using an mde file and will be notified by a pop up window that x days have elapsed and the file needs to be compacted

any ideas why this code would give the error message 'wrong number of arguments' as soon as the compact button is clicked?' *** Code Start **
Function DoCompact(ReStart As Boolean, Optional pwd As String
Dim strCompacter As Strin
Dim strExePath As Strin
strExePath = SysCmd(acSysCmdAccessDir) & "msAccess.Exe
strCompacter = Chr$(34) & CodeDb.Name & Chr$(34)
& " /cmd" & " " & CurrentDb.Nam
If ReStart = True The
strCompacter = strCompacter & ";True
Els
strCompacter = strCompacter & ";False
End I

If (Len(pwd)) The
strCompacter = strCompacter & ";" & pw
End I
Call Shell(strExePath & " " & strCompacter, vbNormalFocus
End Functio


thank
 
D

Dirk Goldgar

jn said:
i am developing an application for a client, using access 97. i have
placed a compact data base button on the main menu of the
application. the user is using an mde file and will be notified by a
pop up window that x days have elapsed and the file needs to be
compacted.

any ideas why this code would give the error message 'wrong number of
arguments' as soon as the compact button is clicked?' *** Code Start
***
Function DoCompact(ReStart As Boolean, Optional pwd As String)
Dim strCompacter As String
Dim strExePath As String
strExePath = SysCmd(acSysCmdAccessDir) & "msAccess.Exe"
strCompacter = Chr$(34) & CodeDb.Name & Chr$(34) _
& " /cmd" & " " & CurrentDb.Name
If ReStart = True Then
strCompacter = strCompacter & ";True"
Else
strCompacter = strCompacter & ";False"
End If

If (Len(pwd)) Then
strCompacter = strCompacter & ";" & pwd
End If
Call Shell(strExePath & " " & strCompacter, vbNormalFocus)
End Function



thanks

What is the "On Action" macro or expression of the button on the
toolbar?
 
G

Guest

the compact button on the menu does the following

Private Sub compact_data_base_Click(
On Error GoTo Err_compact_data_base_Clic

Call Application.Run("compacter.docompact", True, "password"

Exit_compact_data_base_Click
Exit Su

Err_compact_data_base_Click
MsgBox Err.Descriptio
Resume Exit_compact_data_base_Clic

End Sub
 
D

Dirk Goldgar

jn said:
the compact button on the menu does the following:

Private Sub compact_data_base_Click()
On Error GoTo Err_compact_data_base_Click

Call Application.Run("compacter.docompact", True, "password")

Exit_compact_data_base_Click:
Exit Sub

Err_compact_data_base_Click:
MsgBox Err.Description
Resume Exit_compact_data_base_Click

End Sub

I gather that, by "menu", you mean a menu *form* of your own
construction, not a commandbar-type menu.

It looks to me as if you're using a modified version of the Compacter
add-in posted on The Access Web at
http://www.mvps.org/access/modules/mdl0030.htm . Is that correct? The
version posted, though, doesn't support password-protected databases,
AFAICT, so someone must have modified it to do so. The first question
that occurs to me to ask is, are you sure it's the right version of
Compacter.mda that is being executed? If you used the line
Call Application.Run("compacter.docompact", True, "password")

to call the original version of the DoCompact routine (from the .mda
posted on the web site):

Function DoCompact(ReStart As Boolean)

then you would naturally get a "wrong number of arguments" message. I
see from your original post that the version of the DoCompact function
you *think* you're executing does have an optional second argument for
the password; I'm just wondering if that's the version you're actually
calling.

If that's not the problem, then I wonder if there was an error
introduced somewhere in modifying the Compacter.mda to accept and
process the password. To investigate that, I'd need to see the complete
contents of the modCompacter module from the Compacter.mda file.
 
G

Guest

you are right about the menu in that it is one i created
i am quite sure i am executing the correct mda because i renamed the original, so there would not be interference

here is the code from the module compacter
Private Const mconERR_FILE_NOT_EXIST = vbObjectError + 1
Private Const mconERR_NO_COMMAND_LINE = vbObjectError + 2
Private Const mconERR_INSTANCE_NOT_FOUND = vbObjectError + 3
Private Const pconQ = """
Private Const mconSTATUS_FORM = "frmStatus
Private mblnReopen As Boolea

Function fCompacter_EntryPoint(
'******************************************
'Name: fCompacter_EntryPoint (Function
'Purpose: Initiate the compact routin
'Author: Dev Ashis
'Date: 04 November 199
'Called by: Autoexec; Boot with Shift down to bypas
'Calls: fCompactDatabase, fSetAccessWindow, frmStatu
'Inputs: Non
'Output: Non
'******************************************
On Error GoTo ErrHandle
Const conERR_GENERIC = vbObjectError +

DoCmd.OpenForm mconSTATUS_FOR

'Hide the main Access windo
Call fSetAccessWindow(SW_HIDE

'Initiate Compact routin
If Not fCompactDatabase(Command) Then
Err.Raise conERR_GENERI

ExitHere
On Error Resume Nex
DoCmd.Qui
Exit Functio
ErrHandler
If Err = conERR_GENERIC The
'do the registering her
Els
MsgBox "Compact routine failed.",
vbCritical + vbOKOnly,
"Critical error
End I
Resume ExitHer
End Functio

Function fCompactDatabase(strMDBNamePath As String) As Boolea
'******************************************
'Name: fCompactDatabase (Function
'Purpose: Close (if Open) and compact an external Jet Databas
'Author: Dev Ashis
'Date: 04 November 199
'Called by
'Calls: API, TempFil
'Inputs: strMDBNamePath - full path to MDB fil
'Output: True on success, False on failur
'******************************************
On Error GoTo Err_Handle
Dim strMsg As Strin
Dim strFileOnly As Strin
Dim strNewFile As Strin
Dim intI As Intege
Dim strTmpName As Strin
Dim intPos As Integer, pos2 As Intege
Dim pwd As Strin
Dim objAccess As Access.Applicatio

'Determine whether we need to reopen the source database or no
'See if the semi colon separater is ther
intPos = InStr(1, strMDBNamePath, ";"
'determine password, if presen
pos2 = InStr(intPos + 1, strMDBNamePath, ";"

If intPos > 0 The
'If string to the right is False, just clos
If (pos2 > 0) The
strTmpName = Mid$(strMDBNamePath, intPos + 1, pos2 - intPos
Els
strTmpName = Right$(strMDBNamePath, Len(strMDBNamePath) - intPos
End I
If (pos2 > 0) The
pwd = Mid$(strMDBNamePath, pos2 + 1
End I
'get a clean name for strmdbnamepat
strMDBNamePath = Left$(strMDBNamePath, intPos - 1

Select Case UCase(strTmpName
Case "FALSE"
mblnReopen = Fals
Case "TRUE"
mblnReopen = Tru
Case Else
'Assume the we have to reope
mblnReopen = Tru
End Selec
'get a clean name for strMDBNamePat
strMDBNamePath = Left$(strMDBNamePath, intPos - 1
Else 'Assume we have to reopen if the option isn't ther
mblnReopen = Tru
End I

'Invalid argument valu
If Len(strMDBNamePath) = 0 Then Err.Raise mconERR_NO_COMMAND_LIN

'File doesn't exis
If Len(Dir(strMDBNamePath)) = 0 Then Err.Raise mconERR_FILE_NOT_EXIS

'strip out the filename from db pat
strFileOnly = Dir$(strMDBNamePath

'Get a unique filename to compact t
strNewFile = TempFile(False

'Try to get a handle to the other Access instanc
Do While objAccess Is Nothin
intI = intI +
If intI = 50 Then Err.Raise mconERR_INSTANCE_NOT_FOUN
Set objAccess = GetObject(strMDBNamePath
DoEvents
Loop

'Close the database and compact it to a new file

'close all open objects
Call sCloseAllObjects(objAccess)

With objAccess
.CloseCurrentDatabase
Call sUpdateStatusForm("Compacting " & vbCrLf & strMDBNamePath & vbCrLf _
& " to " & vbCrLf & strNewFile)
If (Len(pwd)) Then
DBEngine.CompactDatabase strMDBNamePath, strNewFile, ";pwd =" & pwd
DBEngine.CompactDatabase strMDBNamePath, strNewFile, , , ";pwd=" & pwd
Else
DBEngine.CompactDatabase strMDBNamePath, strNewFile
End If

DoEvents
Kill strMDBNamePath
DoEvents
Call sUpdateStatusForm("Copying " & vbCrLf & strNewFile & vbCrLf _
& " to " & vbCrLf & strMDBNamePath)
FileCopy strNewFile, strMDBNamePath
Do While Len(strMDBNamePath) = 0: DoEvents: Loop

'Only open if specified
If mblnReopen Then
If (Len(pwd)) Then
.OpenCurrentDatabase strMDBNamePath, , pwd
Else
.OpenCurrentDatabase strMDBNamePath
End If
Else
.DoCmd.Quit
End If
Kill strNewFile
End With

fCompactDatabase = True
Exit_Here:
On Error Resume Next
DoCmd.Close acForm, Forms(mconSTATUS_FORM)
Exit Function
Err_Handler:
fCompactDatabase = False
Select Case Err.Number
Case mconERR_INSTANCE_NOT_FOUND:
strMsg = "The Access instance containing the database " & vbCrLf
strMsg = strMsg & pconQ & strMDBNamePath & pconQ & vbCrLf
strMsg = strMsg & "couldn't be located."
MsgBox strMsg, vbCritical + vbOKOnly, "Access instance not found!"
Case mconERR_NO_COMMAND_LINE:
strMsg = "Invalid database name."
strMsg = strMsg & vbCrLf & vbCrLf & pconQ & pconQ & vbCrLf & vbCrLf
strMsg = strMsg & "Compacter will terminate."
MsgBox strMsg, vbCritical + vbOKOnly, "Invalid database name!"
Case mconERR_FILE_NOT_EXIST:
strMsg = "The database you specified" & vbCrLf
strMsg = strMsg & pconQ & strMDBNamePath & pconQ & vbCrLf
strMsg = strMsg & "doesn't exist." & vbCrLf & " Please check the filename and try again!"
MsgBox strMsg, vbCritical + vbOKOnly, "File not found"
Case 429:
strMsg = "The Compacter utility couldn't locate Access instance!"
MsgBox strMsg, vbExclamation + vbOKOnly, "Access instance not found"
Case Else:
MsgBox "Error: " & Err.Number & ". " & Err.Description, vbExclamation + vbOKOnly, _
"Unknown Error"
End Select
Resume Exit_Here
End Function


Private Sub sCloseAllObjects(objInstance As Access.Application)
'*******************************************
'Name: sCloseAllObjects (Sub)
'Purpose: Close all objects in a database while saving them
'Author: Dev Ashish
'Date: 04 November 1998
'Called by: Any
'Calls: None
'Inputs: objInstance - External Access Instance
'Output: None
'*******************************************
Dim i As Integer, ctr As Container, j As Integer
Dim astrObj(0 To 5) As String
Dim lodb As Database

astrObj(0) = "Tables"
astrObj(1) = "Queries"
astrObj(2) = "Forms"
astrObj(3) = "Reports"
astrObj(4) = "Scripts"
astrObj(5) = "Modules"
On Error Resume Next
With objInstance
Set lodb = .CurrentDb
For i = 0 To 5
Call sUpdateStatusForm("Closing open " & astrObj(i) & " in " & vbCrLf & lodb.Name)
Set ctr = lodb.Containers(astrObj(i))
For j = 0 To ctr.Documents.Count - 1
.DoCmd.Close i, ctr.Documents(j).Name, acSaveYes
Next j
Next i
End With
Set lodb = Nothing
End Sub

Sub sUpdateStatusForm(strText As String)
'Updates the open Status form

With Forms(mconSTATUS_FORM)
!lblStatus.Caption = strText
.Repaint
End With
End Sub
 
D

Dirk Goldgar

I found the error in your code. Actually, I found several errors -- I take it you were in the process of adapting Dev's add-in to work with a database password? -- so I hacked away at the code until it worked. Your immediate error was with this line:

.OpenCurrentDatabase strMDBNamePath, , pwd

That would have given a compile error if you had done a Debug -> Compile Loaded Modules while editing the module, because the OpenCurrentDatabase method doesn't have a third argument. I had to do a little research to find a way of forcing Access to use the database password when opening a new current database. The trick I used was posted on The Access Web, at

http://www.mvps.org/access/modules/mdl0036.htm

Try this version of the module, which seems to work for me:

'----------- start of revised code for module modCompacter -----------
Option Compare Database
Option Explicit
Option Private Module

Private Const mconERR_FILE_NOT_EXIST = vbObjectError + 10
Private Const mconERR_NO_COMMAND_LINE = vbObjectError + 20
Private Const mconERR_INSTANCE_NOT_FOUND = vbObjectError + 30
Private Const pconQ = """"
Private Const mconSTATUS_FORM = "frmStatus"
Private mblnReopen As Boolean

Function fCompacter_EntryPoint()
'*******************************************
'Name: fCompacter_EntryPoint (Function)
'Purpose: Initiate the compact routine
'Author: Dev Ashish
'Date: 04 November 1998
'Called by: Autoexec; Boot with Shift down to bypass
'Calls: fCompactDatabase, fSetAccessWindow, frmStatus
'Inputs: None
'Output: None
'*******************************************
On Error GoTo ErrHandler
Const conERR_GENERIC = vbObjectError + 1

DoCmd.OpenForm mconSTATUS_FORM

'Hide the main Access window
Call fSetAccessWindow(SW_HIDE)

'Initiate Compact routine
If Not fCompactDatabase(Command) Then _
Err.Raise conERR_GENERIC

ExitHere:
On Error Resume Next
DoCmd.Quit
Exit Function
ErrHandler:
If Err = conERR_GENERIC Then
'do the registering here
Else
MsgBox "Compact routine failed.", _
vbCritical + vbOKOnly, _
"Critical error"
End If
Resume ExitHere
End Function

Function fCompactDatabase(strMDBNamePath As String) As Boolean
'*******************************************
'Name: fCompactDatabase (Function)
'Purpose: Close (if Open) and compact an external Jet Database
'Author: Dev Ashish
'Date: 04 November 1998
'Modified by: jn; Dirk Goldgar
'Modified to: Accept database password in strMDBNamePath,
' compact using database password
'Mod Date: 17 Noxember, 2003
'Called by:
'Calls: API, TempFile
'Inputs: strMDBNamePath - full path to MDB file
'Output: True on success, False on failure
'*******************************************
On Error GoTo Err_Handler

Dim strMsg As String
Dim strFileOnly As String
Dim strNewFile As String
Dim intI As Integer
Dim strTmpName As String
Dim intPos As Integer, pos2 As Integer
Dim pwd As String
Dim objAccess As Access.Application
Dim dbTemp As DAO.Database

'Determine whether we need to reopen the source database or not
'See if the semi colon separater is there
intPos = InStr(1, strMDBNamePath, ";")
'determine password, if present
pos2 = InStr(intPos + 1, strMDBNamePath, ";")

If intPos > 0 Then
'If string to the right is False, just close
If (pos2 > 0) Then
strTmpName = Mid$(strMDBNamePath, intPos + 1, pos2 - intPos)
Else
strTmpName = Right$(strMDBNamePath, Len(strMDBNamePath) - intPos)
End If
If (pos2 > 0) Then
pwd = Mid$(strMDBNamePath, pos2 + 1)
End If
'get a clean name for strmdbnamepath
strMDBNamePath = Left$(strMDBNamePath, intPos - 1)

Select Case UCase(strTmpName)
Case "FALSE":
mblnReopen = False
Case "TRUE":
mblnReopen = True
Case Else:
'Assume the we have to reopen
mblnReopen = True
End Select
'get a clean name for strMDBNamePath
strMDBNamePath = Left$(strMDBNamePath, intPos - 1)
Else 'Assume we have to reopen if the option isn't there
mblnReopen = True
End If

'Invalid argument value
If Len(strMDBNamePath) = 0 Then Err.Raise mconERR_NO_COMMAND_LINE

'File doesn't exist
If Len(Dir(strMDBNamePath)) = 0 Then Err.Raise mconERR_FILE_NOT_EXIST

'strip out the filename from db path
strFileOnly = Dir$(strMDBNamePath)

'Get a unique filename to compact to
strNewFile = TempFile(False)

'Try to get a handle to the other Access instance
Do While objAccess Is Nothing
intI = intI + 1
If intI = 50 Then Err.Raise mconERR_INSTANCE_NOT_FOUND
Set objAccess = GetObject(strMDBNamePath)
DoEvents
Loop

'Close the database and compact it to a new file

'close all open objects
Call sCloseAllObjects(objAccess)

With objAccess
.CloseCurrentDatabase
Call sUpdateStatusForm("Compacting " & vbCrLf & strMDBNamePath & vbCrLf _
& " to " & vbCrLf & strNewFile)
If (Len(pwd)) Then
DBEngine.CompactDatabase strMDBNamePath, strNewFile, dbLangGeneral & ";pwd=" & pwd, , ";pwd=" & pwd
Else
DBEngine.CompactDatabase strMDBNamePath, strNewFile
End If

DoEvents
Kill strMDBNamePath
DoEvents
Call sUpdateStatusForm("Copying " & vbCrLf & strNewFile & vbCrLf _
& " to " & vbCrLf & strMDBNamePath)
FileCopy strNewFile, strMDBNamePath
Do While Len(strMDBNamePath) = 0: DoEvents: Loop

'Only open if specified
If mblnReopen Then
If (Len(pwd)) Then
Set dbTemp = .DBEngine.OpenDatabase(strMDBNamePath, False, False, ";pwd=" & pwd)
.OpenCurrentDatabase strMDBNamePath
dbTemp.Close
Set dbTemp = Nothing
Else
.OpenCurrentDatabase strMDBNamePath
End If
Else
.DoCmd.Quit
End If
Kill strNewFile
End With

fCompactDatabase = True
Exit_Here:
On Error Resume Next
DoCmd.Close acForm, Forms(mconSTATUS_FORM)
Exit Function
Err_Handler:
fCompactDatabase = False
Select Case Err.Number
Case mconERR_INSTANCE_NOT_FOUND:
strMsg = "The Access instance containing the database " & vbCrLf
strMsg = strMsg & pconQ & strMDBNamePath & pconQ & vbCrLf
strMsg = strMsg & "couldn't be located."
MsgBox strMsg, vbCritical + vbOKOnly, "Access instance not found!"
Case mconERR_NO_COMMAND_LINE:
strMsg = "Invalid database name."
strMsg = strMsg & vbCrLf & vbCrLf & pconQ & pconQ & vbCrLf & vbCrLf
strMsg = strMsg & "Compacter will terminate."
MsgBox strMsg, vbCritical + vbOKOnly, "Invalid database name!"
Case mconERR_FILE_NOT_EXIST:
strMsg = "The database you specified" & vbCrLf
strMsg = strMsg & pconQ & strMDBNamePath & pconQ & vbCrLf
strMsg = strMsg & "doesn't exist." & vbCrLf & " Please check the filename and try again!"
MsgBox strMsg, vbCritical + vbOKOnly, "File not found"
Case 429:
strMsg = "The Compacter utility couldn't locate Access instance!"
MsgBox strMsg, vbExclamation + vbOKOnly, "Access instance not found"
Case Else:
MsgBox "Error: " & Err.Number & ". " & Err.Description, vbExclamation + vbOKOnly, _
"Unknown Error"
End Select
Resume Exit_Here
End Function


Private Sub sCloseAllObjects(objInstance As Access.Application)
'*******************************************
'Name: sCloseAllObjects (Sub)
'Purpose: Close all objects in a database while saving them
'Author: Dev Ashish
'Date: 04 November 1998
'Called by: Any
'Calls: None
'Inputs: objInstance - External Access Instance
'Output: None
'*******************************************
Dim i As Integer, ctr As Container, j As Integer
Dim astrObj(0 To 5) As String
Dim lodb As Database

astrObj(0) = "Tables"
astrObj(1) = "Queries"
astrObj(2) = "Forms"
astrObj(3) = "Reports"
astrObj(4) = "Scripts"
astrObj(5) = "Modules"
On Error Resume Next
With objInstance
Set lodb = .CurrentDb
For i = 0 To 5
Call sUpdateStatusForm("Closing open " & astrObj(i) & " in " & vbCrLf & lodb.Name)
Set ctr = lodb.Containers(astrObj(i))
For j = 0 To ctr.Documents.Count - 1
.DoCmd.Close i, ctr.Documents(j).Name, acSaveYes
Next j
Next i
End With
Set lodb = Nothing
End Sub

Sub sUpdateStatusForm(strText As String)
'Updates the open Status form

With Forms(mconSTATUS_FORM)
!lblStatus.Caption = strText
.Repaint
End With
End Sub
'----------- end of revised code for module modCompacter -----------

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

you are right about the menu in that it is one i created.
i am quite sure i am executing the correct mda because i renamed the original, so there would not be interference.

here is the code from the module compacter:
Private Const mconERR_FILE_NOT_EXIST = vbObjectError + 10
Private Const mconERR_NO_COMMAND_LINE = vbObjectError + 20
Private Const mconERR_INSTANCE_NOT_FOUND = vbObjectError + 30
Private Const pconQ = """"
Private Const mconSTATUS_FORM = "frmStatus"
Private mblnReopen As Boolean

Function fCompacter_EntryPoint()
'*******************************************
'Name: fCompacter_EntryPoint (Function)
'Purpose: Initiate the compact routine
'Author: Dev Ashish
'Date: 04 November 1998
'Called by: Autoexec; Boot with Shift down to bypass
'Calls: fCompactDatabase, fSetAccessWindow, frmStatus
'Inputs: None
'Output: None
'*******************************************
On Error GoTo ErrHandler
Const conERR_GENERIC = vbObjectError + 1

DoCmd.OpenForm mconSTATUS_FORM

'Hide the main Access window
Call fSetAccessWindow(SW_HIDE)

'Initiate Compact routine
If Not fCompactDatabase(Command) Then _
Err.Raise conERR_GENERIC

ExitHere:
On Error Resume Next
DoCmd.Quit
Exit Function
ErrHandler:
If Err = conERR_GENERIC Then
'do the registering here
Else
MsgBox "Compact routine failed.", _
vbCritical + vbOKOnly, _
"Critical error"
End If
Resume ExitHere
End Function

Function fCompactDatabase(strMDBNamePath As String) As Boolean
'*******************************************
'Name: fCompactDatabase (Function)
'Purpose: Close (if Open) and compact an external Jet Database
'Author: Dev Ashish
'Date: 04 November 1998
'Called by:
'Calls: API, TempFile
'Inputs: strMDBNamePath - full path to MDB file
'Output: True on success, False on failure
'*******************************************
On Error GoTo Err_Handler
Dim strMsg As String
Dim strFileOnly As String
Dim strNewFile As String
Dim intI As Integer
Dim strTmpName As String
Dim intPos As Integer, pos2 As Integer
Dim pwd As String
Dim objAccess As Access.Application

'Determine whether we need to reopen the source database or not
'See if the semi colon separater is there
intPos = InStr(1, strMDBNamePath, ";")
'determine password, if present
pos2 = InStr(intPos + 1, strMDBNamePath, ";")

If intPos > 0 Then
'If string to the right is False, just close
If (pos2 > 0) Then
strTmpName = Mid$(strMDBNamePath, intPos + 1, pos2 - intPos)
Else
strTmpName = Right$(strMDBNamePath, Len(strMDBNamePath) - intPos)
End If
If (pos2 > 0) Then
pwd = Mid$(strMDBNamePath, pos2 + 1)
End If
'get a clean name for strmdbnamepath
strMDBNamePath = Left$(strMDBNamePath, intPos - 1)

Select Case UCase(strTmpName)
Case "FALSE":
mblnReopen = False
Case "TRUE":
mblnReopen = True
Case Else:
'Assume the we have to reopen
mblnReopen = True
End Select
'get a clean name for strMDBNamePath
strMDBNamePath = Left$(strMDBNamePath, intPos - 1)
Else 'Assume we have to reopen if the option isn't there
mblnReopen = True
End If

'Invalid argument value
If Len(strMDBNamePath) = 0 Then Err.Raise mconERR_NO_COMMAND_LINE

'File doesn't exist
If Len(Dir(strMDBNamePath)) = 0 Then Err.Raise mconERR_FILE_NOT_EXIST

'strip out the filename from db path
strFileOnly = Dir$(strMDBNamePath)

'Get a unique filename to compact to
strNewFile = TempFile(False)

'Try to get a handle to the other Access instance
Do While objAccess Is Nothing
intI = intI + 1
If intI = 50 Then Err.Raise mconERR_INSTANCE_NOT_FOUND
Set objAccess = GetObject(strMDBNamePath)
DoEvents
Loop

'Close the database and compact it to a new file

'close all open objects
Call sCloseAllObjects(objAccess)

With objAccess
.CloseCurrentDatabase
Call sUpdateStatusForm("Compacting " & vbCrLf & strMDBNamePath & vbCrLf _
& " to " & vbCrLf & strNewFile)
If (Len(pwd)) Then
DBEngine.CompactDatabase strMDBNamePath, strNewFile, ";pwd =" & pwd
DBEngine.CompactDatabase strMDBNamePath, strNewFile, , , ";pwd=" & pwd
Else
DBEngine.CompactDatabase strMDBNamePath, strNewFile
End If

DoEvents
Kill strMDBNamePath
DoEvents
Call sUpdateStatusForm("Copying " & vbCrLf & strNewFile & vbCrLf _
& " to " & vbCrLf & strMDBNamePath)
FileCopy strNewFile, strMDBNamePath
Do While Len(strMDBNamePath) = 0: DoEvents: Loop

'Only open if specified
If mblnReopen Then
If (Len(pwd)) Then
.OpenCurrentDatabase strMDBNamePath, , pwd
Else
.OpenCurrentDatabase strMDBNamePath
End If
Else
.DoCmd.Quit
End If
Kill strNewFile
End With

fCompactDatabase = True
Exit_Here:
On Error Resume Next
DoCmd.Close acForm, Forms(mconSTATUS_FORM)
Exit Function
Err_Handler:
fCompactDatabase = False
Select Case Err.Number
Case mconERR_INSTANCE_NOT_FOUND:
strMsg = "The Access instance containing the database " & vbCrLf
strMsg = strMsg & pconQ & strMDBNamePath & pconQ & vbCrLf
strMsg = strMsg & "couldn't be located."
MsgBox strMsg, vbCritical + vbOKOnly, "Access instance not found!"
Case mconERR_NO_COMMAND_LINE:
strMsg = "Invalid database name."
strMsg = strMsg & vbCrLf & vbCrLf & pconQ & pconQ & vbCrLf & vbCrLf
strMsg = strMsg & "Compacter will terminate."
MsgBox strMsg, vbCritical + vbOKOnly, "Invalid database name!"
Case mconERR_FILE_NOT_EXIST:
strMsg = "The database you specified" & vbCrLf
strMsg = strMsg & pconQ & strMDBNamePath & pconQ & vbCrLf
strMsg = strMsg & "doesn't exist." & vbCrLf & " Please check the filename and try again!"
MsgBox strMsg, vbCritical + vbOKOnly, "File not found"
Case 429:
strMsg = "The Compacter utility couldn't locate Access instance!"
MsgBox strMsg, vbExclamation + vbOKOnly, "Access instance not found"
Case Else:
MsgBox "Error: " & Err.Number & ". " & Err.Description, vbExclamation + vbOKOnly, _
"Unknown Error"
End Select
Resume Exit_Here
End Function


Private Sub sCloseAllObjects(objInstance As Access.Application)
'*******************************************
'Name: sCloseAllObjects (Sub)
'Purpose: Close all objects in a database while saving them
'Author: Dev Ashish
'Date: 04 November 1998
'Called by: Any
'Calls: None
'Inputs: objInstance - External Access Instance
'Output: None
'*******************************************
Dim i As Integer, ctr As Container, j As Integer
Dim astrObj(0 To 5) As String
Dim lodb As Database

astrObj(0) = "Tables"
astrObj(1) = "Queries"
astrObj(2) = "Forms"
astrObj(3) = "Reports"
astrObj(4) = "Scripts"
astrObj(5) = "Modules"
On Error Resume Next
With objInstance
Set lodb = .CurrentDb
For i = 0 To 5
Call sUpdateStatusForm("Closing open " & astrObj(i) & " in " & vbCrLf & lodb.Name)
Set ctr = lodb.Containers(astrObj(i))
For j = 0 To ctr.Documents.Count - 1
.DoCmd.Close i, ctr.Documents(j).Name, acSaveYes
Next j
Next i
End With
Set lodb = Nothing
End Sub

Sub sUpdateStatusForm(strText As String)
'Updates the open Status form

With Forms(mconSTATUS_FORM)
!lblStatus.Caption = strText
.Repaint
End With
End Sub
 
G

Guest

hi, thank you very much for all your work. however, i am now getting the error message '3031 - not a valid password
i am developing this app in office 97 in a windows 98 environment

i checked the code you sent 2x to make sure i had keyed everything correctly. also made sure the origina
compacter.mda was renamed, so i knew i would be executing the correct version

this is the code that activates the compacter routine from my application
Private Sub compact_data_base_Click(
On Error GoTo Err_compact_data_base_Clic
Call Application.Run("compacter.docompact", True
Exit_compact_data_base_Click
Exit Su
Err_compact_data_base_Click
MsgBox Err.Descriptio
Resume Exit_compact_data_base_Clic
End Su

this call generates the invalid password message
if you put

Call Application.Run("compacter.docompact", True,"password"

you get a wrong number of arguments message

thank
 
G

Guest

i forgot to mention in the last email that the compact routine is almost done when it fails
it is operating on compacting the database to c:\\windows\temp\tmpt1a0.tmp
when it gets here, the not valid password message appears.
 
D

Dirk Goldgar

jn said:
hi, thank you very much for all your work. however, i am now getting
the error message '3031 - not a valid password' i am developing this
app in office 97 in a windows 98 environment.

i checked the code you sent 2x to make sure i had keyed everything
correctly. also made sure the original compacter.mda was renamed, so
i knew i would be executing the correct version.

this is the code that activates the compacter routine from my
application.
Private Sub compact_data_base_Click()
On Error GoTo Err_compact_data_base_Click
Call Application.Run("compacter.docompact", True)
Exit_compact_data_base_Click:
Exit Sub
Err_compact_data_base_Click:
MsgBox Err.Description
Resume Exit_compact_data_base_Click
End Sub

this call generates the invalid password message.
if you put

Call Application.Run("compacter.docompact", True,"password")

you get a wrong number of arguments message.

thanks

It works for me. If you are working with a password-protected database
then you would certainly have to use that latter version of the call to
DoCompact, specifying the password. But you say it gives you a "wrong
number of arguments" message. I am forced to conclude that you are
*not* executing the same version of the Compacter.mda, though you may
think otherwise. Did you uninstall it and reinstall it using the Add-In
Manager? Go to the folder in which Microsoft Access is installed and
look there for a copy of Compacter.mda; if this is not the current
version, delete it and then reinstall the add-in.
 
G

Guest

i uninstalled the mda in access, re installed the mda. clearly knew it was the right one because it wa
the only mda on the machine. used the code of call application.run("compacter.docompact",true,"password"

ran the job and now get the error message 'variable not defined ' but no variable name is given

how does the code assign the database password, that i keyed in the application, to the "password" area in the above call
i am using a 4 letter password
as i say i went over the code 2x before i sent earlier emails. have gone over it again and do see any differences with what you provided. the users have to have a command button to do compacts on the mde file
 
D

Dirk Goldgar

jn said:
i uninstalled the mda in access, re installed the mda. clearly knew
it was the right one because it was
the only mda on the machine. used the code of call
application.run("compacter.docompact",true,"password")

ran the job and now get the error message 'variable not defined ' but
no variable name is given.

Hmm, I didn't get that message. Did you say earlier that you *keyed in*
the revised module code I posted? I wonder if you made a keying error.
I suggest you go back and use copy/paste to replce the code in the .mda
with the exact module code I posted. Keying that much text is too
error-prone.
how does the code assign the database password, that i keyed in the
application, to the "password" area in the above call?

It doesn't! You have to insert the correct database password in that
line of code. For example, if your database password is "xyzzy", you
must write

Application.Run("Compacter.DoCompact", True, "xyzzy")

There may be a way to extract the database password from the database
your code is running in, but unless you're running Access 97 I don't
know what it is.
 
G

Guest

so if the password is changed by the admin via the user, the admin must go in an change the "password"
in the mda file as well as the actual access app
 
G

Guest

FINALLY, it works. I had 2 versions of the mda file, one in a personal folder and one in microsoft access.
once i got rid of the access one and copied the one i had been working on, as well as reinstall in the app, the
the compact works.


thank you very much for staying with me and helping me out.

j
 
G

Guest

i think i said in a previous email that if the password changes, that the mda must be changed
i meant to say the call routine in the app
 
D

Dirk Goldgar

jn said:
FINALLY, it works. I had 2 versions of the mda file, one in a
personal folder and one in microsoft access. once i got rid of the
access one and copied the one i had been working on, as well as
reinstall in the app, the the compact works.

Well, that *is* what I told you to do. :)
thank you very much for staying with me and helping me out.

You're welcome.
 
D

Dirk Goldgar

jn said:
i think i said in a previous email that if the password changes, that
the mda must be changed. i meant to say the call routine in the app.

I'm afraid so: since the password is hard-coded in the code, if you
change the database password, you have to change the code. I don't know
any good way around that, unless you want to build password-cracking
code into the application. There may be a simpler way to determine what
the database password is from code running inside that database, but I
don't know it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top