VBA to set buttons caption on closing of pop up form (1 Viewer)

tmyers

Well-known member
Local time
Today, 07:08
Joined
Sep 8, 2020
Messages
1,090
I am trying to run:
Code:
Private Sub Form_Close()

Form!JobQuote!FloatingPriceBtn.Caption = "Pop Out Price Comparison"
Forms!JobQuote!TypeSumComparisonQry.Visible = True


End Sub

This is resulting is some wonky things. It seems to work once, then not again. So I think I am referring to the main form "jobquote" incorrectly. I am creating the illusion that on a button click, a sub-form "pops up" and off the page. That way if the user wants to keep viewing that form, but navigate to a different tab they can.

For the record just in case, my main for is using:
Code:
Private Sub FloatingPriceBtn_Click()

If Me.FloatingPriceBtn.Caption = "Pop Out Price Comparison" Then
    DoCmd.OpenForm "FloatingPriceComparison", acFormDS, , , , acDialog
    Me.TypeSumComparisonQry.Visible = False
    Me.FloatingPriceBtn.Caption = "Close Price Comparison"
Else
    Me.FloatingPriceBtn.Caption = "Close Price Comparison"
    DoCmd.Close acForm, "FloatingPriceComparison"
    Me.TypeSumComparisonQry.Visible = True
    Me.FloatingPriceBtn.Caption = "Pop Out Price Comparison"
End If

End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:08
Joined
Oct 29, 2018
Messages
21,357
Hi. Are you saying you're opening a form as a popup, but it's already also a subform to a main form? What is the code supposed to do and what wonky things is it doing instead?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:08
Joined
May 7, 2009
Messages
19,169
since it is Modal, you cannot Set any property of the button,
so it is better to set it's property before the Modal form opens.
and reset it after you it is closed:
Code:
Private Sub FloatingPriceBtn_Click()

If Me.FloatingPriceBtn.Caption = "Pop Out Price Comparison" Then
    Me.TypeSumComparisonQry.Visible = False
    Me.FloatingPriceBtn.Caption = "Close Price Comparison"
    DoCmd.OpenForm "FloatingPriceComparison", acFormDS, , , , acDialog
    Me.TypeSumComparisonQry.Visible = True
    Me.FloatingPriceBtn.Caption = "Pop Out Price Comparison"
Else
    Me.FloatingPriceBtn.Caption = "Close Price Comparison"
    DoCmd.Close acForm, "FloatingPriceComparison"
    Me.TypeSumComparisonQry.Visible = True
    Me.FloatingPriceBtn.Caption = "Pop Out Price Comparison"
End If

End Sub
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 11:08
Joined
Jul 9, 2003
Messages
16,244
I have a code example that might do what you want, but your question isn't clear.

More information and better explanation is required.
 

tmyers

Well-known member
Local time
Today, 07:08
Joined
Sep 8, 2020
Messages
1,090
Hi. Are you saying you're opening a form as a popup, but it's already also a subform to a main form? What is the code supposed to do and what wonky things is it doing instead?
Yes. I essentially made the same form twice. One is used as the sub-form on my main form. The second one has its pop-up property set to yes and IS NOT a sub-form anywhere. When the button is clicked, it opens the second form, which is a pop up, sets the sub-forms visibility to false to hide it, then sets the buttons caption accordingly.

The problem I have is in the first set of code for the on close event. It may work the first time, but then it wont work at all. I think it may be because I am not correctly referring to the main form/sub-form correctly. What I am trying to achieve is during the on close of the pop up form, change the button on the main forms caption back to its "normal" value then set the sub-forms visibility back to true. Make it look like the form "re-anchored" back onto the main form even though they are two entirely different forms.

The error I get is it "cant find the field 'JoBQuote' referred to in your expression". I am just trying to cover if they close the form via the X rather than the button.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 11:08
Joined
Jul 9, 2003
Messages
16,244
This line :-
Code:
Forms!JobQuote!TypeSumComparisonQry.Visible = True

Code:
Should be:-
Form!JobQuote!TypeSumComparisonQry.Visible = True
 

Users who are viewing this thread

Top Bottom