473,387 Members | 1,440 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,387 software developers and data experts.

Subform not showing when there is no data

Seth Schrock
2,965 Expert 2GB
I have an Access 2010 database that is based on MS SQL Server through ODBC. There are a some times when I will open a form that has a subform and I will go to a record where there is no data in the related table for the current record and the subform will not be there. The box for the control is there, but the subform is not. This doesn't always occur, which makes it tough for me to figure out what is the common denominator that makes it work once and then not another time. I have never had trouble with this when using Access as the backend so I'm assuming that there is something with either MS SQL Server or just ODBC connections in general that is causing this.

One example of this happening consistently is when I add a user, the subform is only visible if they are a certain type of user. When first creating the user, I have the subform set to visible = False. In the EmployeeType combobox's AfterUpdate event I check to see if the type selected was the type that needs this subform and if it is, then I make the subform visible. When this happens, only the subform control become visible, but not the form (which is empty this this is a new employee being entered). I have to go to another employee's record and then come back to the one I just created and then I see the sub form itself and can add the data needed in it. This happens every time. There is another situation with a subform on a different form whose Visible property never changes, but occasionally it isn't visible. So far this only occurs when there is no data.

Is there something that I can do to make these subforms always be visible even if there is no data?
May 3 '13 #1
11 8801
nico5038
3,080 Expert 2GB
Hmm, I've run into trouble when the linked table doesn't have a unique index in MS SQL. So first check or the subform's table has such a unique index.
Next make sure the dataentry property for the subform is set.

Personally I often INSERT a childrow into the subform's table (with the mainform's ID) to allow easy update by the user, however this requires a DELETE when the user cancel the INSERT of the mainform. In your case the selection of the Type can trigger such an INSERT.

Nic;o)
May 4 '13 #2
Seth Schrock
2,965 Expert 2GB
Both tables (for the parent and subform) have primary keys set.

When you say, "make sure the dataentry property for the subform is set" I assume you mean set to no (which it is). Otherwise, existing data isn't shown.

What data do you put in the subform automatically? I picture this causing confusion for my users when they create a record in the main form and then there is already a record in the subform.
May 4 '13 #3
nico5038
3,080 Expert 2GB
Dataentry itself should be "No", but you need to allow addition of records ofcourse.

I picture triggering an INSERT when the Type is selected. This also requires a DELETE when there's a change of Type, but effectively the addition becomes an Update of an existing record and this approach saved me a lot of time looking for why records don't appear.

Possibly I would "split" the mainform and the subform in having a mainform with a datasheet subform with all Employees and besides that different action buttons like:
Add TypeA
Add TypeB, etc.
Update
Delete
Print
etc.
Thus when clicking the [Employee Add TypeA] button you can show the proper form with or without the subform.

Having such a mainform with employees will allow the user to use the right-click popup menu to filter the employees and easily find one(s) that needs to be updated. And this approach is rather common in many applications.

Nic;o)
May 4 '13 #4
Seth Schrock
2,965 Expert 2GB
What do you INSERT? Triggering it from the Type AfterUpdate event sounds like a good idea, but I don't want to insert wrong data and then trust that the user will leave the record with the subform correct since this is the form that grants access to certain areas of the database.
May 6 '13 #5
nico5038
3,080 Expert 2GB
I insert a default record into the child table.
When closing the form the user has two options:
1) Cancel, which will require to delete the record.
2) Save, what will trigger the code to validate the record and when OK nothing has to be done as the data will be stored automatically.
Additionally you'll need to check or the selected value from the combobox does need a child record and by default (when some values do have children and some not) I would drop all rows from the child table holding the mainform's unique identifier.

Just curious, what's the function of this record that the user needs to leave correct?

Nic;o)
May 6 '13 #6
Seth Schrock
2,965 Expert 2GB
I guess I could create a record that didn't do anything that if it is left in the subform wouldn't change anything.

The main form is the employee form and one of the fields is the employee type. If the type is Loan Processor, then I have the subform appear which lists the loan types that the selected processor can do. Thus, I wouldn't want a record inserted that listed a real loan type since the loan processor might not be able to do that loan type and then I would be counting on the user entering the employee to either change or delete the record to make sure that the permissions were set correctly. Besides, if the data isn't correct, then what good is it since you can't trust it?
May 7 '13 #7
nico5038
3,080 Expert 2GB
Hmm, I guess there are multiple loan types that can be selected for an employee and in a normalized datastructure you would have one row for each loantype and an indicator "Valid Yes/No".

I would have created a tblLoanType with just the LoanType and ValidYN fields (Set to "No") and use these to insert all loantypes for such a "Loan Processor" employee.
Then the user gets a filles subform and is able to check the appropriate loan types. When the employee type is changed you can delete these records or set all ValidYN fields to False.

In the processing you can filter the loantype records for a ValidYN field to be true for further processing and ignore the "No" records...

Getting the idea ?

Nic;o)
May 7 '13 #8
twinnyfo
3,653 Expert Mod 2GB
Seth,

Did you try Nico's suggestion in post 4 above, to AllowAdditions set to Yes on the subform? I have come across your problem previously, and that seems to do the trick.

Regards,
twinnyfo
May 7 '13 #9
Seth Schrock
2,965 Expert 2GB
@Twinny All the settings are correct to allow me to edit, add and delete records. My problem is not in editing or adding records, but in having the subform appear inside the subform control.

@Nico I think that I understand what you are doing. What I could do is just insert every loan type into the join table and then the subform would have a set of records. The user would then only have to check a checkbox to give them permission to use that loan type. It would create more headaches in that if I would add a loan type later on, it would make it so that I would have to code an append query to insert the new loan type for each loan processor into the joining table (between the loan type and employee table). I'll have to think about it before I implement it, but I think that I could do that. Seems complicated to have to do all that just to make a subform show up.
May 7 '13 #10
nico5038
3,080 Expert 2GB
An easy help for the insert you can use a query like:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblLoanLink ( PersNr, LoanType, ValidYN )
  2. SELECT 123 AS PersNr, tblLoantype.LoanType, tblLoantype.ValidYN, *
  3. FROM tblLoantype;
  4.  
By executing this from code (CurrentDB.Execute command) you can replace the 123 with the needed ID.

Nic;o)
May 7 '13 #11
I have had the same problem: Primary key present in table, recordset type set to dynaset, allow additions enabled on the form, and it just went blank when no data present (updates worked fine on existing data). What solved it for me, was to include the primary key column in the select statement of the record source. It is not enough to have it in the table. This part seems to be missing from the internet sources i could discover,
Jun 23 '15 #12

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

Similar topics

1
by: ali asjad | last post by:
is there any event that is raised when data in datagrid is changed. actually im using a dataset filled through data adapter and is the data source of datagrid Posted Via Usenet.com Premium...
2
by: nic | last post by:
Hi I am currently having problems getting two forms to behave the way I want. I have two tables Student and Application, and their respective forms. (Tables)Student has StudentID (PK) & an...
3
by: Bob Darlington | last post by:
I have a subform (one of 3) on a main (unbound) form. The problem sf is the first one on the form, and one the user uses to select a record on which data in the other 2 sf's are based. All sf's...
0
by: Tony Williams | last post by:
I have a main form based on "tblmonth" which has a control "txtmonthlabela" (based on a field of the same name) My subform based on a query "qryFDAsubform" which is based on my table "tblmaintabs"...
10
by: Rigs | last post by:
Hi, I have a textbox with a Custom Validator that utilizes the OnServerValidate method for that textbox. This works fine, however the method only executes when data exists in that textbox after...
9
by: ApexData | last post by:
My main form has tab-pages. On each tabbed page is a subform control containing a different subform. When a user selects a specific tab and begins to edit a record, I need a way of preventing the...
1
by: Colin Clark | last post by:
Hello, I have a database of scores for a sports club. I want to display a continuous subform showing a person's scores for the season along with a running calculation based on those scores (the...
4
by: jmartmem | last post by:
I have an Access 2002 main form ("Project Initiation Checklist") with a subform ("sfPICMilestone"). The Link Child Field is ID and the Link Master Field is also ID. The linked field is an...
5
by: JHite | last post by:
I’m using Access 2003 on Windows XP. I have a Mainform (Staff Entry) which displays an unbound combo box named ChooseStaff. The Row Source for this combo box is a SELECT of the UserIDs and Staffer...
2
by: ruth m | last post by:
I have inserted three tab controls on a form and wish to insert a different subform on each tab page. I have inserted the first subform (order details) - however, the problem is that it appears on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.