Really Weird Unexplainable Error!

saross

Registered User.
Local time
Today, 08:40
Joined
Mar 4, 2003
Messages
120
Hi, I've got a really strange problem I can't solve with one of my macros. Will try to explain best I can:

From frmSelectContact macro behind a button opens dialog frmInputSubUser1.
Having selected an item from the combo list box in the latter form, macro behind a button as follows:

OpenForm frmAddSubUserToOrg
SetValue (passes orgID from frmInputSubUser1 to frmAddUserToOrg)
Close frmInputSubUser1
Close frmSelectContact
Maximise

The thing is, I get an error message saying it can't find frmSelectContact. So I took that line out, and frmSelctContact stays on top of the others. Is there something really obvious I'm doing wrong?
 
Is frmSelectContact Modal? If so make it a regular window and try it.
 
Think that
From inputsubuser1

you are opening one form and closing 2
problem is that you are closing inputsubuser1 and then trying to close frmSelectContact
but
the form that is carrying the code i.e inputsubuser1 is closed and so you are trying to run a command from a form that is actually closed and Access is getting confused so simply says. Cannot find it

Try switching the two close commands around

Len B
 
Tried both but still same error message!
 
saross said:
I get an error message saying it can't find frmSelectContact. So I took that line out, and frmSelctContact stays on top of the others. Is there something really obvious I'm doing wrong?

Could it be your spelling?
 
Oops found it. You are going to be sore about this one


frmSelectContact
or
frmSelctContact

spellings ????

Dyslectics of the world untie

Happens to us all

Len B
 
Erm... I don't think that's it. Don't forget I'm creating macros not code so I'm just using the drop down lists to select the names of the forms to close, open etc. I know I've spelt it wrong in my posting but I've checked the macro and it's not wrong there. It's been driving me crazy for 2 days!
 
Convert your macro to VBA and post it here:
 
This is the converted macro:

Function mcrAddSubUserToOrg()
On Error GoTo mcrAddSubUserToOrg_Err
Dim intOrgID As Integer

intOrgID = Forms!FrmInputSubUser1!Combo7

DoCmd.OpenForm "FrmAddSubUserToOrg", acNormal, "", "", , acNormal
Forms!FrmAddSubUserToOrg!OrgID = intOrgID
DoCmd.Close acForm, "FrmSelectContact"
DoCmd.Close acForm, "FrmInputSubUser1"


mcrAddSubUserToOrg_Exit:
Exit Function

mcrAddSubUserToOrg_Err:
MsgBox Error$
Resume mcrAddSubUserToOrg_Exit

End Function

Have just tried the following sub and that brings up the same error message:
Private Sub Command3_Click()
On Error GoTo Command3_Click_Err
Dim intOrgID As Integer

intOrgID = Forms!FrmInputSubUser1!Combo7

DoCmd.OpenForm "FrmAddSubUserToOrg", acNormal, "", "", , acNormal
Forms!FrmAddSubUserToOrg!OrgID = intOrgID
DoCmd.Close acForm, "FrmSelectContact"
DoCmd.Close acForm, "FrmInputSubUser1"


Command3_Click_Exit:
Exit Sub

Command3_Click_Err:
MsgBox Error$
Resume Command3_Click_Exit
End Sub
 
Incidentally, I have a cancel button on the same form which runs a macro to
Close frmSelectContact
Open frmMain

And this works fine! It's only with the other I get an error message saying it can't find Select Contact after it's closed it!
 
saross said:
Have just tried the following sub and that brings up the same error message:

Now, set checkpoints on the code and step through it, observing values.

Do these forms have their respective OnLoad events which could be throwing the error?
 
FrmSelect did have a Maximize macro in it's OnCurrent property but I already removed that and still the same problem.
 
Mile-O-Phile said:

Now, set checkpoints on the code and step through it, observing values.

Erm... I don't know how to do this... :o
 
Click on the grey bar to the left of your code, and a red line should appear (except on Dim statements and comments.)

When you run the code (since you put it on your button) the code will stop at each line and, if you hover the mouse over variables, etc, you can follow the code through step by step.
 
Also, comment out the On Error Goto... line and the code will stop at the exact line that is causing the problem.
 
Wow that's handy to know! Thanks.:)

The value is passed to intOrgID fine. Everything works ok until it comes to the line to close the FrmSelectContact at which point it just says it can't find it - but it gives the error message AFTER it's closed it. I commented that line out and the error message disappeared but the FrmSelectContact is then sitting there bold as brass!
 
Put these three lines in a standalone module:

Code:
Function IsFormOpen(strFormName As String) As Boolean
    IsFormOpen = (SysCmd(acSysCmdGetObjectState, acForm, strFormName) = acObjStateOpen)
End Function


Now, put this code behind your button (the OnError is deliberately commented out):

Code:
Private Sub Command3_Click() 

    'On Error GoTo Command3_Click_Err 

    Dim intOrgID As Integer 

    intOrgID = Forms!FrmInputSubUser1!Combo7 

    DoCmd.OpenForm "FrmAddSubUserToOrg", acNormal
    Forms!FrmAddSubUserToOrg!OrgID = intOrgID
    If IsFormOpen("FrmSelectContact") Then
        MsgBox "FrmSelectContact is open. Will close now."
        DoCmd.Close acForm, "FrmSelectContact"
    End If

    If IsFormOpen("FrmInputSubUser1") Then
        MsgBox "FrmInputSubUser1 is open. Will close now."
        DoCmd.Close acForm, "FrmInputSubUser1"
    End If


Command3_Click_Exit: 
    Exit Sub 

Command3_Click_Err: 
    MsgBox Error$ 
    Resume Command3_Click_Exit 
End Sub

See how that goes...that'll give messages to say the forms are open and we can see what happens.
 
Thank you.
I pasted the code and the messageboxes appeared at appropriate times and forms closed down when I clicked OK. THEN the error message came up afterward - so for some reason it's looking for FrmSelectContact AFTER it's been closed down. But it has no reason to as far as I can tell. The relevant values have already been copied over...
 
Got an example of this in Access '97?
 
Database is in Access 2k and it's HUGE. Is there a way to copy the relevant bits over and save them as A97?
 

Users who are viewing this thread

Back
Top Bottom