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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determining active control on form

Status
Not open for further replies.

ytakbob

Programmer
Jul 20, 2000
105
US
I have a click event that executes a common subroutine that opens a form with an activexcontrol on it. (the calendar).
ANyhow....I would like to determine the control and value from which this common subroutine was called.

orderssubform controls are startdate or enddate and these 2 controls via the click event can call the
selectdate subroutine. The subroutine opens a form (frmcalendar) which at load sets the activexcal.value to either now() or (and this is what I'm trying to do->) the value that the ordersubform control already had in it....I just don't know how to determine AND "pass" or reference the orderssubfform control name and value. Bob Schmid
bob_schmid@hmis.org
330-746-1010 ext. 1347
 
Something like...

Sub cmdOpen_Click()

If screen.PreviousControl.Name = "StartDate" then
MySubOpenForm Me.txtBeginDate

elseif Screen.PreviousControl.Name = "EndDate" then
MySubOpenForm Me.txtEndDate
end if

End Sub

Function MySubOpenForm(MyDate as String)

If IsDate(MyDate) then
Docmd.OpenForm "MyForm"
Forms![MyForm].Subform.Form.MycontrolName = MyDate
End if

End Function

Hope that helps.

Gary
gwinn7
 
close.
THe above code when placed in the subroutine that opens
frmcalendar gives me the value "orderssubform" which is the name of the form, not the control on the form. Bob Schmid
bob_schmid@hmis.org
330-746-1010 ext. 1347
 
Hmm! OK, then in the afterupdate event of both date controls you could set a "controlname" variable with the name of the control that was last updated. Then, reference that variable to determine which field was updated last. The rest are just debugging details to reset the variable properly.

Can't think of another way at the moment.

Gary
gwinn7
 
A variation on Gary's would be to set a date variable with the first form and call it along with the open event of the second form.

I built a form with a command button and a text box (frm1) and a second form with an activeXctl calendar (frm2).

The following public function checks for a value in the textbox and the command button's click event opens frm2 and passes the value to the activeXctl. If there's no value in the textbox, the variable is set to the curent date.
Code:
____________________________________
  Public Function frmDate()
  Dim mydate As Date
  mydate = Nz(Text1, Date)
  frmDate = mydate
  End Function
____________________________________
  Private Sub Command0_Click()
  DoCmd.OpenForm "frm2"
  [Forms]![frm2].[ActiveXCtl2].Value = frmDate
  End Sub
____________________________________

I'm thinking you could use your click events to set the value for frmDate...


HTH



John

Use what you have,
Learn what you can,
Create what you need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top