473,394 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Have to close main form to update data

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
6 919
Please... is there Any news?
Jan 10 '17 #2
jforbes
1,107 Expert 1GB
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
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
1,107 Expert 1GB
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
you mean I need to remove the loop action?
Jan 12 '17 #6
jforbes
1,107 Expert 1GB
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

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

Similar topics

7
by: Danielb | last post by:
I want my application to run most of the time as just an notify icon visible in the system tray, with some dialogs windows that open if the user selects an option from the context menu on the tray...
3
by: Nathan | last post by:
I read an earlier post from Gary and answered by Peter Huang concerning closing one form and showing another. I need to do the same thing in my application, but the code Peter gave didn't work for...
1
by: sparks | last post by:
I have a main form that people are putting name and address etc in. Now I need to put some unbound fields on the sub forms to display this data to them. Its fine on current records but on a new...
2
by: Narvs | last post by:
I have a main form with information on people hired and on this form I have a button that you click to term an employee which opens a new dialog window to enter a term date. Now it doesn't remove...
1
by: solargovind | last post by:
Hi, In my main form, i have one Combo box called "Student_name" which displays Stud_id & Stud_name. When i select particular student name, i need to display their City in the Subform's text box. ...
16
by: mlcampeau | last post by:
I'm fairly new to this so I'll try to be as clear as possible. I have a database that stores employee information and all job titles available. I have a main form that is based from a query and...
6
by: CJONES | last post by:
I have a main form and use a combo box to open a pop up form. The combo box lists customers and only one customer requires the fields that are found on the pop up form. I can get the form to pop...
11
by: banderson | last post by:
Hello, I know I've seen an answer to this question before, but I cannot seem to find it again. After searching for a few hours, I've decided to re-post in hopes someone can give advice and/or send...
9
Microblitz
by: Microblitz | last post by:
Two weeks (Well about 8 hours actually) into writing VBA code and I've run up against a problem. This is the senario; ---- I have a "Main" form in which an entry on a drop down selects one of...
7
by: massamiya | last post by:
Please help me. I have hit a brickwall and can't figure out what the problem is I have a main form call (Prods)and subform called Prodsub and both are unbound. I call the Mainform from a "start...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.