Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

subform and form

Status
Not open for further replies.

demax182

Technical User
Jul 13, 2004
43
US
Hi again,

I have a main form, subform 1, and subform 2 all nested within each other. Subform 2 being the grandchild. I have a date field in subform 2 that I would like to fill out using the calendar control. Instead of having to make another calendar control within subform 2, I would like this field refer to the calendar control I have in subform 1. I tried using Me.Parent!ocxCalendar.visible = true, but that doesn't work. I keep getting errors when I click MouseDown. Is there any way of doing this?
 
demax182

frmParent -> sbfrmChild -> sbfrmGrandchild

...And you want sbfrmGrandchild to reference a date in sbfrmChild ??

(Which makes me curious why you use Me.Parent!ocxCalendar.visible = true since this makes the field visible or not - are you trying to re-use the same code? More on this later)

I suspect there are three approaches to referencing the date in the second subform, sbfrmChild.

- Reference the absolute name
=Forms!sbfrmChild!ocxCalendar

- Reference the relative name
=Me.Parent.ocxCalendar

- Use DLookUp to grab the stored value for the sbfrmChild
=DlookUp("[YourDateFld]", "TableForsbfrmChild", "[YourLinkFieldID] = " & Me.YourLinkField_sbfrmGrandchild)

...Okay, that answers how to reference the date in the subform.

If you are trying to re-use the code from the subform, sbfrmChild, you should really use a Public module, or better yet, a Function call.

The Function, say DisplayCal, opens up the calendar, the end user selects the date, and the function returns the date to the calling variable.

Code:
Function DisplayCal () as Date

Dim datSelect  as Date

'... Your calendar program code goes here
'... Assigns value to datSelect

DisplayCal = datSelect  

End Function

Then call the function - you can call the function from within VBA code, or as the DataSource for a field

Code:
If CDate(DisplayCal()) Then
...

Or
Code:
=CDate(DisplayCal())

You add some versatility to the DisplayCal () function by passing a variable - for example, to display current month, last month, last year. The passed value could be optional or mandatory.

I use the CDate function to ensure a date is passed. You have to watch out if the end user Cancels out from selecting a valid date.

Richard

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top