Need advices on passing tabbed subform name and control name to fMiniCalendar

B

Bon

Hello all

I have a fMiniCalendar module. If I click the calendar icon, it will
pop-up Mini Calendar.

When the fMiniCalendar is triggered, it will returns the date into a
textbox on the form. This works fine when the form is a parent
(frmMain). But, i got an error "The form/subform cannot be found" if I
put the calendar icon in the tabbed subform (frm_screenpart).

The command button code i tried to refer a control in tabbed subform:
Call fMiniCalendar(, , "frmMain!frm_screenpart", "DOB")

Where frmMain is the parent form, frm_screenpart is the subform in
frmMain and DOB is the text field on the tabbed subform frm_screenpart
that the returned date value goes.

Under debug mode, the error stops at this line:
Forms(FormName)(FieldName) = CombinedDate

How can i make it work? Please give me some advices.

Thanks

Bon
 
B

Brendan Reynolds

Here are two examples. The first procedure takes the name of the form, the
name of the subform control, and the name of the text box as strings. The
second example takes a single argument, a reference to the text box. Because
this is a reference to the original text box, we can simply assign a value
to the reference in order to have that value displayed in the text box, we
do not need to know anything about the form that contains the text box.

Public Sub Test1(ByVal FormName As String, _
ByVal SubformControlName As String, _
ByVal TextboxName As String)

Dim frm As Form
Dim sfr As SubForm
Dim txtTest As TextBox

Set frm = Forms(FormName)
Set sfr = frm.Controls(SubformControlName)
Set txtTest = sfr.Form.Controls(TextboxName)
txtTest.Value = Date

End Sub

Public Sub Test2(MyTextBox As TextBox)

MyTextBox.Value = Date

End Sub

Here are examples that show how to call each of the two procedures above.
Here, 'sfrTest' is the name of the subform control. Don't forget that the
name of the control may not be the same as the name of the form that it
contains.

Private Sub Command1_Click()

Test1 Me.Name, "sfrTest", "txtTest"

End Sub

Private Sub Command2_Click()

Test2 Me.sfrTest.Form.Controls("txtTest")

End Sub
 

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