Compile Problem (1 Viewer)

Martyh

Registered User.
Local time
Today, 10:34
Joined
May 2, 2000
Messages
196
Hi all,
I am using MS Access 2010.
I am trying to create a form that will change the captions in another form. See Fig 1. There are only 2 procedures: Load and Close

1) Q1.1.1 is the command button with the correct caption put in to place. (cmdQ1)

2) The [Caption] row is the caption that I would make the changes to (tCaption01)

3) The [Question No] row is irrelevant to the problem.

When I open the form, the unbound text (tCaption01) reads the data from fQuestions_Trial_2 (the other form):
Code:
    Me.tCaption01 = Forms!fQuestions_Trial_2!cmdQ1.Caption

When I close the form, it checks to see whether the 2 “captions” are not equal, and makes the change if so.

Code:
If Me.tCaption01 <> Me.cmdQ1.Caption Then
    Forms!fQuestions_Trial_2!cmdQ1.Caption = Me.tCaption01
End If
Here is my problem:

The first time into the form there seems to be no problem, but then I haven’t changed any of the captions, just got the existing captions from the other form.

However, on subsequent times thru the form, I get the error “Run time error 2450: MS Access cannot find the referenced form “fQuestions_Trial_2”. “ - This is the form that I am getting the captions from. See Fig 2.

I can remedy the problem by going into the form in Design mode and decompiling/recompiling the form (“fQuestions_Trial_2”), however no where can I find a place where I can do the same thing in code.

Question: Is there a way to compile the form BUT IN CODE, or is there something else that I am missing?

Thanks,
Marty

PS Sorry about the not including any code -- rules!!
 

Attachments

  • Fig 1.jpg
    Fig 1.jpg
    17 KB · Views: 39
  • Fig 2.jpg
    Fig 2.jpg
    16.4 KB · Views: 40

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:34
Joined
May 7, 2009
Messages
19,247
you should probably do it in the Unload event of the form, not in Close. on the Unload event all the values of your control is still intact, while on the Close event, it has already done some housekeeping and destroyed the controls and their values.
 

Martyh

Registered User.
Local time
Today, 10:34
Joined
May 2, 2000
Messages
196
I misspoke ---> there is only 1 event : Load
the other event is on a button called "Close" and never really in the "On Close" event of the form.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:34
Joined
May 7, 2009
Messages
19,247
if so you code should work.
also, you can put an instance of that form to a variable

dim f as access.form
private form_load
set f=Forms!fQuestions_Trial_2.Form
end sub

private sub form_unload()
If Me.tCaption01 <> Me.cmdQ1.Caption Then
f!cmdQ1.Caption = Me.tCaption01
End If
end sub
 

Martyh

Registered User.
Local time
Today, 10:34
Joined
May 2, 2000
Messages
196
No it still seems to give me the same error as before, but stops on:

Private Sub form_load()
Set f = Forms!fQuestions_Trial_2.Form


it seems to have something to do with turning the "Design Mode" on and off in the VBA screen.
I'm investigating ...
 
Last edited:

Martyh

Registered User.
Local time
Today, 10:34
Joined
May 2, 2000
Messages
196
Does the secondary file have to open? i.e. Forms!fQuestions_Trial_2.Form
 

Users who are viewing this thread

Top Bottom