Form with Pop-Up Form (1 Viewer)

mreference

Registered User.
Local time
Today, 16:42
Joined
Oct 4, 2010
Messages
137
Hi, I have form (MAIN FORM) with a field that performs a Dcount on a table, if the value of that field is greater than 1, a command button will appear underneath that allows the user to open a pop-up form (POPUP FORM) with the records associated with the Dcount.

If the user deletes the records on the POPUP FORM, when they close the form, I used the following VBA on the close button to refresh the MAIN FORM which works perfectly, and the MAIN FORM will update the Dcount.

Forms!frmProduct_Detail_Add.Form.Refresh

However, the command button on the main form that is only visible if the Dcount value is greater than 1, does not disappear when the Dcount value updates to 0 from the refresh if the user deletes the records.

I have included the following VBA on the MAIN FORM on these events

On Current
On Open
the Dcount Field

If Me.txtItemstoOrder > 0 Then
Me.cmdStocktoOrder.Visible = True
ElseIf Me.txtItemstoOrder = 0 Then
Me.cmdStocktoOrder.Visible = False
End If

I just can't get this button to hide if the value reverts to 0 after the user has deleted the records, and clicking on the button with no records brings up an error and a very odd looking Pop-Up form not in the position I set it to appear.

I also tried closing the MAIN FORM and reopening it, but as I have a number automatically generated on a data entry form, when it opens it doesn't reopen the record I was working on.

Any help would be appreciated
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,131
See if the activate event works. I'd put the code in a form level function and call it from the other events.
 

mreference

Registered User.
Local time
Today, 16:42
Joined
Oct 4, 2010
Messages
137
See if the activate event works. I'd put the code in a form level function and call it from the other events.
Would you have an example of how this works as I'm not understanding where to put the code, my brain is fried trying to resolve this :)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,131
My first suggestion was to try your same code in the activate event of the main form to see if it resolves your problem.
 

mreference

Registered User.
Local time
Today, 16:42
Joined
Oct 4, 2010
Messages
137
Thanks, I just tried and it didn't hide the command button

Private Sub Form_Activate()
If Me.txtItemstoOrder > 0 Then
Me.cmdStocktoOrder.Visible = True
ElseIf Me.txtItemstoOrder = 0 Then
Me.cmdStocktoOrder.Visible = False
End If
End Sub
 

bastanu

AWF VIP
Local time
Today, 08:42
Joined
Apr 13, 2010
Messages
1,402
As Paul suggested could you try to put the code in a form public sub
Code:
Public Sub sbShowHideButton()
If Me.txtItemstoOrder > 0 Then
    Me.cmdStocktoOrder.Visible = True
Else
    Me.cmdStocktoOrder.Visible = False
End If
End Sub
then in the close event of the popup add a call to it after refreshing the main form:
Code:
Forms!frmProduct_Detail_Add.Form.Refresh
Call Forms!frmProduct_Detail_Add.Form.sbShowHideButton

Cheers,
 

mreference

Registered User.
Local time
Today, 16:42
Joined
Oct 4, 2010
Messages
137
As Paul suggested could you try to put the code in a form public sub
Code:
Public Sub sbShowHideButton()
If Me.txtItemstoOrder > 0 Then
    Me.cmdStocktoOrder.Visible = True
Else
    Me.cmdStocktoOrder.Visible = False
End If
End Sub
then in the close event of the popup add a call to it after refreshing the main form:
Code:
Forms!frmProduct_Detail_Add.Form.Refresh
Call Forms!frmProduct_Detail_Add.Form.sbShowHideButton

Cheers,
Hi Vlad, thank you joining the thread.

So I placed the code
Code:
Call Forms!frmProduct_Detail_Add.Form.sbShowHideButton
where you suggested and it told me that there was a compile error at Forms!frm....., so i removed the ! and swapped it to Forms.frm..... and it seemed to accept it.

The code you asked me to place in a form public sub, I created a module first and put it there, but got a run-time error 2465 Application-defined or object-defined error, so put it in the MAIN FORM and received the same runtime error.

Have I placed the code in the correct place and/or by putting Forms.frm...., did that cause the problem?

regards
 

mreference

Registered User.
Local time
Today, 16:42
Joined
Oct 4, 2010
Messages
137
Mission accomplished after tweaking your code

Instead of
Code:
Call Forms!frmProduct_Detail_Add.Form.sbShowHideButton

I used
Code:
Call Forms.frmProduct_Detail_Add.sbShowHideButton

The other code was placed in the MAIN FORM.

Cheers both for your help
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,131
Glad you got it working.
 

bastanu

AWF VIP
Local time
Today, 08:42
Joined
Apr 13, 2010
Messages
1,402
Great news! Because it uses "Me." the public sub should be in the form with the button you are trying to show/hide and it looks you got it in the right place.

Cheers,
 

Users who are viewing this thread

Top Bottom