By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,911 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

Have to close main form to update data

P: 5
I have main form (FrmProjects) and subform (FrmProducts)
I Put this code on load on the subform
Dim RstFrmProduct As Recordset
Set RstFrmProduct = Form_FrmProductsSubform.Form.Recordset
Do While Not RstFrmProduct.EOF

If CboCategory = 1 Then
Form_FrmProjects.Buttonl.Visible = True
End If

If CboCategory = 2 Then
Form_FrmProjects.Button2.Visible = True
End If

RstFrmProduct.MoveNext

Loop
End Sub

and I put a button3 on main form to open button1 and button2 tabcontrol

The problem is when I add a record in the subform and hit button3, doesn't update button1 and button2
I have to close main form and re open it to update

please help
Jan 9 '17 #1
Share this Question
Share on Google+
6 Replies


P: 5
Please... is there Any news?
Jan 10 '17 #2

jforbes
Expert 100+
P: 1,107
A button on a Continuous Form really only has one instance. This means that when you set the Visibility for one Button on the Continuous Form, you set the Visibility for all the displayed buttons on that Form. There's not a way in Access to turn Visibly off and on by Row on a Continuous Form. This article details what you are running into a little more: Why Values in Unbound Form Controls Don't Persist

So, basically, you can't do what you are attempting to do. Instead, I would recommend one of the following:
  • Leaving all your Buttons Enabled and in code for the Button click, check to see if the code should be ran and if not, let the user know or ignore the button click.
  • Create TextBoxes to replace your buttons. Use Conditional Formatting to "Hide" your Controls by setting the Text and Background color to white or whatever your background color is for the Detail section of the SubForm. You could then change the Code to test to see if the code can run and if not it would exit without doing anything.
.
Jan 10 '17 #3

P: 5
First of all thanks a lot for your reply
I am afraid there is a misunderstanding here
The buttons 1 and 2 are on a "tabcontrol" on the main form. while button 3 is on the main form itself.

The subform is linked to the mainform
Jan 12 '17 #4

jforbes
Expert 100+
P: 1,107
Yeah, there is was lot of confusion. I was attempting to understand why you would write a for each loop on every record and then use it to update buttons on the UI. In the past, this is usually attempted to update controls on a SubForm. But now knowing that the buttons are not on the SubForm it changes the picture quite a bit.

First thing to address is that your code will eventually make both Button1 and Button2 visible and it will never hide the buttons. The code would needed to be more like this:
Expand|Select|Wrap|Line Numbers
  1. If CboCategory = 1 Then
  2.     Form_FrmProjects.Buttonl.Visible = True
  3. Else
  4.     Form_FrmProjects.Buttonl.Visible = False
  5. End If
  6.  
  7. If CboCategory = 2 Then
  8.     Form_FrmProjects.Button2.Visible = True
  9. Else
  10.     Form_FrmProjects.Button2.Visible = False
  11. End If
It can be simplified to:
Expand|Select|Wrap|Line Numbers
  1. Form_FrmProjects.Buttonl.Visible = (CboCategory = 1)
  2. Form_FrmProjects.Button2.Visible = (CboCategory = 2)
I would go about what you are doing in a different way. I think even if you get you code to work, it will only update the button's visibility based on the Last Record of the SubForm. Secondly, it will only update the Button's visibility when the user clicks the button. Typically, you want this type of thing being done automatically as the user navigates through the SubForm records.

There is a couple different ways to do this. The simplest is to move this code to the SubForm OnCurrent Event and to the CboCategory After Update Event:
Expand|Select|Wrap|Line Numbers
  1. Form_FrmProjects.Buttonl.Visible = (CboCategory = 1)
  2. Form_FrmProjects.Button2.Visible = (CboCategory = 2)
The OnCurrent Event will update the buttons as the user clicks on different records in the SubForm. The AfterUpdate event will update the buttons as the user edits the record.
Jan 12 '17 #5

P: 5
you mean I need to remove the loop action?
Jan 12 '17 #6

jforbes
Expert 100+
P: 1,107
Yep, unless I'm missing something, the loop doesn't do anything except move you to the last record of the SubForm, so that you can get the value of CboCategory from the last Record shown on the SubForm.

But, typically buttons are hidden and shown based on the currently selected record instead of the last record of the SubForm. If this differs from what you are attempting, let us know.
Jan 12 '17 #7

Post your reply

Sign in to post your reply or Sign up for a free account.