How do I initialise a date field in a dialogue or form?

I have a dialogue (dialog?) with a date field, and I want to fill in today’s date before displaying it. So the macro which is displaying it has code like

  D=Now()
  oDateControl=odialog.GetControl("datDate")
REM This gives a runtime error "Object variable not set"
  oDateControl.Setdate(D)
REM This has no effect on the value of the Date field in the control
  oDateControl.Date.Day=Day(D)
  oDateControl.Date.Month=Month(D)
  oDateCOntrol.Date.Year=Year(D)

But neither of these work for the reasons in the comments. Sorry for the formatting, but the “CODE” button doesn’t seem to work properly.

Edited for clarity. Please use Preformatted Text tool on toolbar for code.

I tried to use Preformatted Text and it gave me what you originally saw! Don’t know why. Thanks for sorting it out.

Sometimes you need to add spaces to the beginning of each line. Observe the Preview area before submitting. This will show the actual posting from your input.

I did see the preview, but couldn’t find a way of getting properly formatted text.

Change: oDateControl.Setdate(D) to oDateControl.View.setText(D).

Here are a couple of posts for reference:

Dialogs & Dates

Clearing Dates