What's the problem?

Tay

likes garlic
Local time
Today, 14:51
Joined
May 24, 2002
Messages
269
I really hope someone out there can help.....

I have a database which holds information about the progress of schemes. I have a main form holding info common to all schemes, and then depending upon the type of scheme, a subform specific to that scheme type will appear.
I found some code on here today which is brilliant. It highlights each control when it has the focus, so makes users lives that bit easier.
The code works perfectly for all main forms, but as soon as I enter the subform via the main form , I get an error message saying
"Access can't find the form "whatever" referred to in a macro or vb code.
The form you referenced may be closed or may not exist in this database.
Access may have encountered a compile error in a vb module for the form."
If I just go to the subform, the code does what it is supposed to.
It would be really helpful if I could get this to work, especially as the subforms are the main place where information is entered.

Here is the code I am using.

Option Compare Database
Option Explicit

Public Function TextGotFocus(strFrmName As String, strCtrlName As String)
Dim frm As Form
Dim ctrl As Control

Set frm = Forms(strFrmName)
frm.Controls(strCtrlName).BackColor = 13619151
Set frm = Nothing
End Function
Public Function TextLostFocus(strFrmName As String, strCtrlName As String)
Dim frm As Form
Dim ctrl As Control

Set frm = Forms(strFrmName)
frm.Controls(strCtrlName).BackColor = vbWhite
Set frm = Nothing
End Function

Sub Formfiller(StrForm As String)
Dim dbs As Database
Dim frm As Form
Dim ctrl As Control

Set dbs = CurrentDb()
DoCmd.OpenForm StrForm, acDesign
Set frm = Forms(StrForm)

For Each ctrl In frm.Controls
If ctrl.ControlType = acTextBox Then
ctrl.OnGotFocus = "=TextGotFocus(""" & frm.Name & """,""" & ctrl.Name & """)"
ctrl.OnLostFocus = "=TextLostFocus(""" & frm.Name & """,""" & ctrl.Name & """)"
End If
Next ctrl

DoCmd.Close acForm, StrForm, acSaveYes
End Sub

In the debug window, I enter all the relevant forms names as
formfiller("frmwhatever").

Any ideas on what I should do?
TIA:confused:
 
For reasons that are not clear to me, Access does not seem to view the form displayed in a subform control as actually being open, even though it is open from the user's perspective.

Try referencing controls on the subform like this:

[main form name]![name of subform control on main form].Form![name of control on subform]

It's important to distinguish between the subform control, and the form which that control displays. So, if your main form was named Form1, your subform was named Form2, the subform control on the main form was named sbfrmHenry, and the control you were actually trying to reference on the subform was named txtJune, you would reference it like this:

[Form1]![sbfrmHenry].[Form]![txtJune]

Note that the name of the subform itself appears nowhere in this reference.
 
Thanks for that Alan; at least I know what the problem is now. Still can't get it to do what I want, but I'll perservere.
 

Users who are viewing this thread

Back
Top Bottom