Initialize a variable in form_load

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I initialize a variable in a form_load subroutine when the form is opned up. I've got the following error when I do that: "You can’t reference a property or method for a control unless the control has the focus". I am using a combobox to link one of the table fields and attached to a calendar to show the dates

Any help will be greatly appreciated

Gerald
 
Gerald,

You're not very clear, so I'm just guessing here... are you trying to assign
a value to a control on the form? If yes, are you using an expression like:
Me.ControlName.Value = something
Me.ControlName = something
i.e. take out the Value property reference (it's the one that requires that
the control has the focus). Referring to a control without specifying a
property references its value by default.

If this is not the case, please post back (in the same thread) giving more
details.

HTH,
Nikos

If that's the case, then just change the expression to:
GDL said:
How can I initialize a variable in a form_load subroutine when the form is
opned up. I've got the following error when I do that: "You can't reference
a property or method for a control unless the control has the focus". I am
using a combobox to link one of the table fields and attached to a calendar
to show the dates.
 
Thank you very much for the reply. I did not state very clear
I have a control as combo box which initalized as a date value. This control also tied with a table field
How can I initalize this control so that when user open this form this field is empty for example so that
it will force the user to make a selection

Thanks agai
Geral
 
OK, got you.

Use the form's On Current event to run the following code (assumption: combo
name cboDate):

If Me.NewRecord = True Then
Me.cboDate = Null
Me.cboDate.SetFocus
End If

The If statement will make sure the code is only run when a new record is
being created, so it doesn't clear the stored value in existing records.


Then use the combo's On Lost Focus event to run the following code, to force
the user to enter a date:

If IsNull(Me.cboDate) Then
msgbox "Please enter date!", cbExclamation, "Missing Data"
Me.cboDate.SetFocus
End If

HTH,
Nikos

GDL said:
Thank you very much for the reply. I did not state very clear.
I have a control as combo box which initalized as a date value. This
control also tied with a table field.
How can I initalize this control so that when user open this form this
field is empty for example so that
 
Back
Top