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

Subform won't show when adding a new record to main form.

DJRhino1175
221 128KB
Not sure what happened, but cannot figure out why its not working at this point. I attached the database so anyone willing to help might be able to tell me what went wrong and what I can do to fix it.

Thanks for any help provided.
Attached Files
File Type: zip OEE Database.zip (1.10 MB, 174 views)
Sep 4 '18 #1

✓ answered by zmbd

DJRhino1175
I do want the subform to show all the time, just one line for a new entry.
Normally, new question new thread; however, in this case I think this is really a refinement of what your actual problem was...

OK,
Because you really intended to have the subform show all of the time I really advise simply removing of the calls to the Function ReSizeForm.

HOWEVER, if you really want to use the function then we can simplify things a bit

We'll remove the optional new record flag and set a minimum subform height.

So you now have:
Form: Frm_FrmLine - On_Current Event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  
  3.      Call ReSizeSubform(frm:=Me)
  4.  
  5. End Sub
and change the function so that you have:
Module: MDLForms - Function ResizeSubform:
Expand|Select|Wrap|Line Numbers
  1. Function ReSizeSubform(frm As Form)
  2.   ' Runs on the OnCurrent of the MAIN Form (FrmLine)
  3.     Dim TotalHeight As Single
  4.     Dim NoRecs As Long
  5. '
  6.     With frm.subfrmDrawing.Form
  7.       If Not .Recordset.EOF Then
  8.         .Recordset.MoveLast
  9.         NoRecs = Nz(.Recordset.RecordCount) + 1
  10.         If NoRecs > MaxRecs Then
  11.           NoRecs = MaxRecs
  12. '         .ScrollBars = 0             ' Show scrollbar
  13. '       Else
  14. '         .ScrollBars = 0             ' end if
  15.         End If
  16.         TotalHeight = .Section(acHeader).Height + .Section(acFooter).Height + (.Section(acDetail).Height * NoRecs)
  17.         If Not .Recordset.BOF Then
  18.           .Recordset.MoveFirst
  19.         End If
  20.       End If
  21.     End With
  22. '
  23.   If TotalHeight < 2415 Then TotalHeight = 2415
  24. '
  25.   frm.subfrmDrawing.Height = TotalHeight
  26.   frm.Repaint
  27. End Function
Line 24, ensures that the subform is always shown regardless of the actual number of child records associated with parent.

Again, the value of 2415 for the subform height is an arbitrary value I used because the 4 record subform was aesthetically pleasing to my eye as I stepped through the records.

10 1428
zmbd
5,501 Expert Mod 4TB
DJRhino1175:
- Please keep in mind that most of use will not d/l files without them being asked for first. Many of us do this during down time at work and there are usually very strict rules about downloading a files.

- You have several forms in this database
Which form are you referring to?
You cannot expect anyone here to wade through your application to find the issue; help us to help you by telling us which forms are the issue and in this case give a bit of detail about how they are related.
Sep 4 '18 #2
DJRhino1175
221 128KB
Sorry ZMBD, I apologize if I broke any rules or protocols. On the start page click the button that says OEE Entry form. That opens "FrmLine". When creating a new record a subform should be showing below the comments box. it doesn't show for a new record, but will show for an old record. The subform is called SubfrmDrawing.
Sep 4 '18 #3
zmbd
5,501 Expert Mod 4TB
Form: FrmLine
Event: On_Current
Calls Module MDLForms - Function ReSizeSubForm
On a new record there are no related records; thus,
frm.subfrmDrawing.Height = TotalHeight
TotalHeight = 0
Therefor the subform is hidden.

I'll take a closer look in a little bit... the lab timer just buzzed :)
Sep 4 '18 #4
DJRhino1175
221 128KB
ZMBD,

I disabled this code and the subform is showing up again, so now I need to look at this code a little closer to find what needs to change so that it at least shows up when there is no records.
Sep 4 '18 #5
zmbd
5,501 Expert Mod 4TB
Change the following:
Form: Frm_FrmLine
On_Current Event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  
  3.     Call ReSizeSubform(frm:=Me, zMeNewRecord:=Me.NewRecord)
  4.  
  5. End Sub
This will allow you to pass a new record flag to the resize function

Module: MDLForms
Function ResizeSubform:
Adding an optional flag with a default of false for new record lets you set the size of the subform to an arbitrary value; running your form a few times I settled on the size for 4 records as the default subform size when on a new record.
Expand|Select|Wrap|Line Numbers
  1. Function ReSizeSubform(frm As Form, Optional zMeNewRecord As Boolean = False)
  2.   ' Runs on the OnCurrent of the MAIN Form (FrmLine)
  3.   '    Dim NoRecs As Integer
  4.     Dim TotalHeight As Single
  5.     Dim NoRecs As Long
  6.   If zMeNewRecord Then
  7.     TotalHeight = 2415
  8.   Else
  9.     With frm.subfrmDrawing.Form
  10.       If Not .Recordset.EOF Then
  11.         .Recordset.MoveLast
  12.         NoRecs = Nz(.Recordset.RecordCount) + 1
  13.         If NoRecs > MaxRecs Then
  14.           NoRecs = MaxRecs
  15. '         .ScrollBars = 0             ' Show scrollbar
  16. '       Else
  17. '         .ScrollBars = 0             ' end if
  18.         End If
  19.         TotalHeight = .Section(acHeader).Height + .Section(acFooter).Height + (.Section(acDetail).Height * NoRecs)
  20.         If Not .Recordset.BOF Then
  21.           .Recordset.MoveFirst
  22.         End If
  23.       End If
  24.     End With
  25.   End If
  26. '
  27.   frm.subfrmDrawing.Height = TotalHeight
  28.   frm.Repaint
  29. End Function
Verify:
Form: FrmLine
Open in design view
Show the form's Property Sheet
In the selection type dropdown select: "subfrmDrawing"
Select the data tab
Verify that [Filter On Empty Master]= Yes
This will ensure that when you are on a new record the subform doesn't simply display the first record(s) in the bound data set.
Sep 4 '18 #6
zmbd
5,501 Expert Mod 4TB
Ok,
Looking at your last post: if you always want the subform to be visible then the modifications I looked at for new record are not needed - instead, don't call Function ReSizeSubform and set the subform area in the parent to the correct size for the desired display.
Sep 4 '18 #7
DJRhino1175
221 128KB
I updated to what you suggested and it all works fine. I do want the subform to show all the time, just one line for a new entry. The second half of the module that was modified was for when adding or deleting lines of data from that sub form. Now I'm curious if I'll need to update the second half of the MDLForms module which handles the After update and on Delete of the subform.
Sep 4 '18 #8
DJRhino1175
221 128KB
I would like to thank you for the help and guidance on repairing this issue.
Sep 4 '18 #9
zmbd
5,501 Expert Mod 4TB
DJRhino1175
I do want the subform to show all the time, just one line for a new entry.
Normally, new question new thread; however, in this case I think this is really a refinement of what your actual problem was...

OK,
Because you really intended to have the subform show all of the time I really advise simply removing of the calls to the Function ReSizeForm.

HOWEVER, if you really want to use the function then we can simplify things a bit

We'll remove the optional new record flag and set a minimum subform height.

So you now have:
Form: Frm_FrmLine - On_Current Event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  
  3.      Call ReSizeSubform(frm:=Me)
  4.  
  5. End Sub
and change the function so that you have:
Module: MDLForms - Function ResizeSubform:
Expand|Select|Wrap|Line Numbers
  1. Function ReSizeSubform(frm As Form)
  2.   ' Runs on the OnCurrent of the MAIN Form (FrmLine)
  3.     Dim TotalHeight As Single
  4.     Dim NoRecs As Long
  5. '
  6.     With frm.subfrmDrawing.Form
  7.       If Not .Recordset.EOF Then
  8.         .Recordset.MoveLast
  9.         NoRecs = Nz(.Recordset.RecordCount) + 1
  10.         If NoRecs > MaxRecs Then
  11.           NoRecs = MaxRecs
  12. '         .ScrollBars = 0             ' Show scrollbar
  13. '       Else
  14. '         .ScrollBars = 0             ' end if
  15.         End If
  16.         TotalHeight = .Section(acHeader).Height + .Section(acFooter).Height + (.Section(acDetail).Height * NoRecs)
  17.         If Not .Recordset.BOF Then
  18.           .Recordset.MoveFirst
  19.         End If
  20.       End If
  21.     End With
  22. '
  23.   If TotalHeight < 2415 Then TotalHeight = 2415
  24. '
  25.   frm.subfrmDrawing.Height = TotalHeight
  26.   frm.Repaint
  27. End Function
Line 24, ensures that the subform is always shown regardless of the actual number of child records associated with parent.

Again, the value of 2415 for the subform height is an arbitrary value I used because the 4 record subform was aesthetically pleasing to my eye as I stepped through the records.
Sep 4 '18 #10
DJRhino1175
221 128KB
zmbd,

Updated the code and all checks out.
Sep 4 '18 #11

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

Similar topics

1
by: Andante.in.Blue | last post by:
Hi everyone! In Access 97, I have a parent form and a subform that are both based on the same query. The main form is continuous and serves up a summary for each record. The subform provides...
1
by: ECathell | last post by:
I am getting an unspecified error when adding a windows form to a project. New project, old project. Doesn't matter. Also happens for user control. All the message box says is Unspecified Error. ...
13
by: bitsnbytes64 | last post by:
Hi, I have a form which contains a subform. Both are were creetd using the form wizard and are bound by the column IXO_NR (on two different tables), which is the control source for a textbox on...
2
xpun
by: xpun | last post by:
hey everyone I was wondering if it was possible to get data form a subform and use it in a conditional in the main form this is what I’ve got so far bu it doesn’t really do anything If...
1
by: Steve | last post by:
This may be a dumb questions please forgive I have a form that shows a list box that links to a table with 7 employee names The form does not show employee key. When adding record to master...
6
by: Kaloyan Krumov | last post by:
I have the following set up: Tables Supplier SupplierContacts Forms SupplierRegform SupplierContacts - subform On the main form I’m using tab control with two tabs. The first tab contains...
3
Seth Schrock
by: Seth Schrock | last post by:
I have a form, frmCustomer, that has a subform, sfrmFileTypes. My problem is that when I'm entering a new customer and the CustomerID is still blank, I don't want the subform to have any data put...
2
by: tamchar | last post by:
I have a form with subform. When the main form is generated the number series of document on field (Called RegNum), and I wont that number series is auto updated to field (called RegNumD) on subform....
4
by: wallacegirl26 | last post by:
I have a sub form that allows me to choose a students ID then the control source is set so the students ID comes up in the main form to allow me to enter data about that specific pupil. however when...
1
by: 28371sandeep | last post by:
I have a main form and a sub form in an access 2007 database. The sub form in inside the main form and master filed and child field are linked so that when the main form in opened, the particular...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.