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

Change Form Caption based on where it's opened from

Status
Not open for further replies.

jazminecat23

Programmer
Mar 16, 2007
103
US
Hi all - how do i reference the button and form location which opens a particular form?

I have a form NameDataEntry which can be opened from 3 different places on my database. Depending on where it's opened from, I want to change certain characteristics of the form, mainly it's caption and backcolor, to make it more clear to the enduser what kind of name they are entering. I have figured out two different approaches to this problem. First, I could put the code in each cmdbutton that opens the form. Second, and this seems smarter, would be to put all of the code in the OnOpen event of my NameDataEntry form, and reference the form from which it is opened. But I don't know how to reference each button. Can anyone point me in the right direction? Thanks!
 

When calling the form, use different OpenArgs argument for each calling form, and then format NameDataEntry depending on which form called it:

DoCmd.OpenForm "NameDataEntry", , , , , , "CallingFormA"

DoCmd.OpenForm "NameDataEntry", , , , , , "CallingFormB"

DoCmd.OpenForm "NameDataEntry", , , , , , "CallingFormC"


Code:
Private Sub Form_Load()
If Len(Nz(Me.OpenArgs, "")) > 0 Then
 
 If Me.OpenArgs = "CallingFormA" Then
      'Formatting code for when FormA calls
  End If

  If Me.OpenArgs = "CallingFormB" Then
      'Formatting code for when FormB calls
  End If

  If Me.OpenArgs = "CallingFormC" Then
      'Formatting code for when FormC calls
  End If

End If

End Sub

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Sweet- that is exactly the bit I was missing. I will work with this tonight and see what I can accomplish. Thank you!
 
Glad to could help! That's why we hang out here on the stoop!

Linq

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top