Form doesn't exist error

A

Anthony

when I open a form I am getting this run-time error: Cannot find Form
'frm_Project_Assign' referred to in a Macro or Visual Basic Code.
When I click "Debug" it goes to the following code:

Private Sub Form_GotFocus()
If Forms!frm_Project_Assign.IsLoaded = True Then
Me.cbo_InCharge_ID.Locked = True
Else
Me.cbo_InCharge_ID.Locked = False
End If
End Sub

The Form 'frm_Project_Assign' clearly exists because it shows up in the
Objects window in the visual basic utility. I checked the spelling a dozen
times and it is correct. Now, when I open up the form where this code
exists, the 'frm_Project_Assign" is not open or loaded at that point. That
is what I am testing.
Can you think of a reason why Access might think a form doesn't exist when
it clearly does? My theory is maybe I am coding the "IF" statement wrong,
but I am not sure.

Thanks
 
K

Klatuu

You are not using the IsLoaded property correctly. Should be:

Private Sub Form_GotFocus()
If CurrentProject.Allforms("frm_Project_Assign").IsLoaded Then
Me.cbo_InCharge_ID.Locked = True
Else
Me.cbo_InCharge_ID.Locked = False
End If
End Sub

But, here is a shorter way to do it:


Private Sub Form_GotFocus()
Me.cbo_InCharge_ID.Locked =
CurrentProject.Allforms("frm_Project_Assign").IsLoaded
End Sub
 
A

Anthony

Thank You for your help and quick response. You have fixed my run-time
error; however, the code is not doing what I thought it would do. I am using
your shorter version of the code. However, the "cbo_InCharge_ID" field (a
combo box) is still allowing me to change data in that field when the
"frm_Project_Assign" form is loaded.

I changed the event to "Me.cbo_InCharge_ID.Enabled" instead of "Locked".
When I do that, it Disables the field BUT if I close the "frm_Project_Assign"
form it won't re-enable the field when I go back to that form (give it the
Focus). hmmmmmm
 
A

Anthony

I have fixed my problem. I moved the GotFocus code to the actual field
property instead of the form property and now it works.
 

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