2
votes

I have a function that has been in use for a number of months that checks to see if the form that is going to be opened will actually have records to be viewed before opening it. Recently I decided to change from ACCDB to ACCDE for security purposes. After making the change over the function started throwing error 2450 "Microsoft Access cannot find the referenced form..." I can't seem to find anything of use online that could tell me what the cause of this error is and why it only happens with ACCDE.

On a side note I realize the inefficiency of the logic in this function, it's on my list.

Public Function ValidateFormToOpen(strFormName As String, strFilter As String, strFieldName As String) As Boolean
On Error GoTo Err_Handler

Dim intNumberOfRecords As Integer

'If the form is currently open count how many results will be shown
If CheckFormState(strFormName) Then
    intNumberOfRecords = DCount(strFieldName, Access.Forms(strFormName).RecordSource, strFilter)

'If it is closed open it in a hidden state and then count how many records would be shown
Else
    DoCmd.OpenForm strFormName, acDesign, "", strFilter, , acHidden
    intNumberOfRecords = DCount(strFieldName, Access.Forms(strFormName).RecordSource, strFilter)
    DoCmd.Close acForm, strFormName
End If

'If there were records that will be shown return true
If intNumberOfRecords > 0 Then
    ValidateFormToOpen = True
Else
    ValidateFormToOpen = False
End If


Exit_Handler:
    Exit Function

Err_Handler:
    Call LogError(Err.Number, Err.Description, strMODULE_NAME & ".ValidateFormToOpen on " & strFormName)
    Resume Exit_Handler
End Function

This is the CheckFormState Code

Public Function CheckFormState(sFormName As String) As Boolean
On Error GoTo Err_Handler

    If Access.Forms(sFormName).Visible = True Then
        CheckFormState = True
    End If


    Exit_Handler:
        Exit Function

    Err_Handler:
        CheckFormState = False
        Resume Exit_Handler
End Function
1
Have you identified which line triggers the error? Could the error be happening in CheckFormState(strFormName)? - HansUp
Unfortunately I can't really tell, once it hits ACCDE I can't debug or anything to figure out what is going on. Though I threw up the code in case you wanted to see it. - Newd
With no way to identify which line triggers the error, you're really up the creek without a paddle. Do not accept that. One measure you can adopt is to add line numbers to your VBA procedures. Then you can use Erl in your error handling (see the help topic for details). You can use MZ-Tools to manage line numbering. You wouldn't even need to number everything; you could number only those procedures which are involved with the problem. - HansUp
An interesting idea, it wouldn't be hard to add even a crude numbering system such as a intCurrentLine variable that gets incremented as code executes and is then included in the error that gets logged. - Newd
It is this line DoCmd.OpenForm strFormName, acDesign, "", strFilter, , acHidden. This line works no problem while in ACCDB format. - Newd

1 Answers

1
votes

An ACCDE format database restricts design capabilities in general. I think that may be why you get an error with this line:

DoCmd.OpenForm strFormName, acDesign, "", strFilter, , acHidden

However I'm not positive that is the complete explanation because when I attempt to open a form in Design View (DoCmd.OpenForm "Form1", acDesign) in my ACCDE database, Access gives me a different error message:

"The command you specified is not available in an .mde, .accde, or .ade database."

So I don't know what the solution is for your goal, but I believe it can not be based on opening a form in Design View.