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

Set variable as current form to avoid explicit reference 1

Status
Not open for further replies.

votegop

Technical User
Feb 22, 2002
127
US
The following code is called from a button on a pop-up form. There may be any one of several identical forms (whose only difference is data source) behind it when the popup closes (via DoneButton). Obviously I need to avoid referring to the underlying form name explicitly. This code does not work(I've bolded the problem), but I've got to be close to the answer. A little help please?!

Private Sub DoneButton_Click()

DoCmd.Close
Dim frmCurrentForm As Form
Dim ctlList As Control
Set frmCurrentForm = Screen.ActiveForm
' Return Control object pointing to list box.
Set ctlList = Forms!frmCurrentForm!contractorfield
' Requery source of data for list box.
ctlList.Requery

End Sub

Thanks.
Jay
 


Set ctlList = Forms(Chr(34) & frmCurrentForm & Chr(34))!contractorfield
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Thanks MichealRed, but I get a compile error: Type mismatch.

The following gets highlighted:

Set ctlList = Forms(Chr(34) & frmCurrentForm & Chr(34))!contractorfield


Jay
 
Rather than using a variable, why not try this:

Code:
Private Sub DoneButton_Click()

    DoCmd.Close
    Dim frmCurrentForm As Form
    Dim ctlList As Control
    ' Return Control object pointing to list box.
    Set ctlList =
Screen.ActiveForm
Code:
!contractorfield
    ' Requery source of data for list box.
    ctlList.Requery
    
End Sub

HTH
Lightning
 
Thanks Lightning! I wouldn't have guessed you could do that...but it works great. [2thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top