PDA

View Full Version : Help with subform



rticehurst
03-21-2009, 10:43 PM
Hi
I am new to VBA but have managed to create a form in Access that works perfectly. It has some code that populates a field on the form with different text dependant on the control that you "mouseover". I did this using the info at msaccesstips.com/2009/02/controltip-text-ad-time-delay.shtml

However, when i add that form to a parent form (ie it becomes a subform) the mouseover no longer works and i get an error pop-up “Microsoft Office Access can’t find the form ‘Details’ referred to in a macro expression or Visual Basic code.”
The subform is called "Details" and the parent form is called "Patients".

Can anyone help?

OBP
03-22-2009, 05:26 AM
When you place a Form on to a mainform and it becomes a Subform it no has the same name for VBA Reference purposes. To refer to it externally (i.e. not from within the Form where you can use the Me. to refer to the form) you have to include the name of the main form.
It can use the syntax of
mainformname.subformname.control
or possibly
forms![mainformname]![subformname].control
although the second version has a lot more restrictions on what you can refer to.
mainformname would be the actual Name of your Mainform and subformname the actual Name of your subform.

rticehurst
03-22-2009, 02:56 PM
Thanks for that. I'm a real newby so don;t fully understand where to put the form names. I've copied some of the code from the Details (sub) form below-

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'ControlTip Me.Name
Dim strtag As String
strtag = "Hover over each intervention type for an example "
If Me.lbltip.Caption <> strtag Then
Me.lbltip.Caption = strtag
End If
End Sub
Private Sub Check218_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
ControlTip Me.Name, Me.Check218.Tag, 1
End Sub
Private Sub Check216_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
ControlTip Me.Name, Me.Check216.Tag, 1
End Sub
There are about 40 different controls in total.

Where exactly do i put the Patients.Details (Parent.sub) as you described??

Thanks

OBP
03-23-2009, 08:40 AM
Does it highlight any particular line of code if you click Debug on the error message?
I would try just one control first and if that works I would use the Edit>Replace function to chnage the others.
So let's take this one

If Me.lbltip.Caption <> strtag Then
Me.lbltip.Caption = strtag
End If

Change it to

If Me.subformname.lbltip.Caption <> strtag Then
Me.subformname.lbltip.Caption = strtag
End If

when you type in the me. and then the first letter of the actual subform name it should offer you the first control starting with that letter and hopefully you will see the subform name in the list.

If you can get one to work you can use use replace me. with me.subformname.