Subform form not visible when record is null

hilbertm

Registered User.
Local time
Today, 00:28
Joined
Sep 7, 2001
Messages
46
I have a subform that displays filtered information. The subform is based on a form that contains a cmd button that allows the user to add additional records to the subform. The problem is that if there are no records in the subform query, the form in the subform does not show, therefore the cmd button on the form is not visible and the user can not add a record to the subform. If there is already a record or records, the form is visible and the user can use the cmd button and add a new record. Is there something simple that I am missing?
 
Is the command button on the sub-form itself? If yes, is it in the header or footer of the subform.

If a subform has no records to display and doesn't allow new records to be directly entered, it will only show the header and footer.

If this is the case, add a footer to your subform and place the command button there.

HTH
smile.gif

SteveA
 
Steve,
Putting the cmd button on the footer of the subform worked. Thanks. I am having another problem with the subform. The subform contains filtered data and the cmd button opens a different form that opens a new record using the filtered data. This only works when a record is already on the subform. Now when I click the cmd button with a record on the subform I can enter a new record that is releated to the recordID on the subform. When there is no data on the subform the new record does not correspond with the record on the main form.
I don't know if I am being very clear, thanks for any ideas.
Mike
 
If the Main form displays an Order, and the subform displays OrderItems, does clicking the command button open a window to add or modify OrderItems related to the current Order?

Cheers,
SteveA
 
Steve,
To answer your question, yes, I think so.
My main form 1 contains airport information. It opens with a query where the user selects the airport to view in a dialog box. Once the form opens, the user can view the instrument procedures at the selected airport on a listbox(on the main form 1). Once the user double clicks on a procedure, a Procedure Main form opens that has a sub form (on a tab control) linked to the procedure on the main form which is linked to the airport info on the main form 1 to show ptas information for each instrument procedure. the user can view ptas information on the sub form.
I am using the following code to open a form for the user to enter data.

Private Sub cmdPtasNew_Click()
On Error GoTo Err_cmdPtasNew_Click
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmPtasNew"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord acDataForm, stDocName, acNewRec
Forms!frmPtasNew!ProcedureID = Me.ProcedureID

Exit_cmdPtasNew_Click:
Exit Sub

Err_cmdPtasNew_Click:
MsgBox Err.Description
Resume Exit_cmdPtasNew_Click

End Sub

I hope this answers your question.
Mike
 
What are you setting stLinkCriteria to?

SteveA
 
I'm not setting the StLinkCriteria at all. It got left in the code after my many cut and paste attempts to get this to work. The code works but only if there is a ptas record for the procedure already. I am also trying to make a cmd button to bring up a new form to edit the current ptas on the subform. BTW, I am very new to VBA and don't really know what I am doing yet, but I have high hopes.
 
The line 'Forms!frmPtasNew!ProcedureID = Me.ProcedureID' is using the subform field ProcedureID to set the Procedure ID on the new form. When you don't have a record displayed in the subform this information is not known.

You need to change Me.ProcedureID to point to the field in the main form rather than the subform ie [Forms].[YourMainForm].[ProcedureID]. This will ensure that the ProcedureID is always passed.

If you change 'Forms!frmPtasNew!ProcedureID' to be 'Forms!frmPtasNew!ProcedureID.DefaultValue', it will allow a user to open the new form without actually adding a record. If they complete any particular field on the new form, the correct ProcedureID will be assigned. If they close the form without entering any data, you don't end up with blank entries in the database.

HTH
SteveA
 
Ok I think it’s late enough for me to be awake enough to try and unravel Double Dutch. I assume ViewPTAS is the sub form based on the query by the same name,and that's the form your now having trouble with. If that’s the case then it’s the query that’s preventing new additions. You may have to remove some of the tables and display them as subs of the sub or change the joins, but I can’t fathom what does what to test the theories.
HTH
 
Rich,
I actually changed all my queries, forms, and field names to not include spaces and try to use the standard naming conventions you mentioned. So some of the database that I sent you has changed, hopefully for the better.
The first form that is viewed is: frmMaintForm, which is called using the query: qryMaintFormByIcao. This query uses the criteria for ICAO [Enter ICAO], which lets the user select the ICAO to view. (ICAO is a 4 letter identifier for airports) So the first form opens after the user selects the airport to view.
There is a list box that contains all the instrument procedures for the airport on the frmMaintForm. I have the list box setup to allow the user to double click on the instrument procedure they want to view details of.
The form that opens is frmHostNationViewProcedure. This is the main form that procdedure information is on. The form is linked to the procedure by the field ProcedureID, so just information for the procedure that was double clicked is shown.
My plan is to have a number of sub forms on the main form (frmHostNationviewProcedure)to display various information for each procedure. One of the sub forms is frmPtasView. (Actually I want to have 4 subforms on different tabs, I just need to figure out how to get the PTAS subform to work first.)
The frmPtasView is the form I used for the PTAS sub form which I named frmPtasViewSubform.
The source object for frmPtasViewSubform is frmPtasView. The link child fields = ProcedureID and the link master fields = ProcedureID
There are 2 cmd buttons on the frmPtasForm, which is the form that is in the subform. They both open a new forms, frmPtasEdit (to edit the ptas that is currently on the subform) and frmPtasNew (to enter a new PTAS for the given procedure).
The code for frmPtasNew is:

Private Sub cmdPtasNew_Click()
On Error GoTo Err_cmdPtasNew_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmPtasNew"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord acDataForm, stDocName, acNewRec
Forms!frmPtasNew!ProcedureID = Me.ProcedureID

Exit_cmdPtasNew_Click:
Exit Sub

Err_cmdPtasNew_Click:
MsgBox Err.Description
Resume Exit_cmdPtasNew_Click

End Sub

This code allows me to enter a new PTAS related to the procedureID of the procedure on the main form (frmHostNationviewProcedure) but only if a PTAS record already exists. If no PTAS record exists for that procedure, then a procedure with a ProcedureID of 0 is called up on the frmPtasNew form.

And I could not get the EditPtas code to work:
Private Sub cmdPtasEdit_Click()
On Error GoTo Err_cmdPtasEdit_Click
DoCmd.OpenForm "frmPtasEdit"
Forms!frmPtasEdit!ProcedureID = Me.ProcedureID
Exit_cmdPtasEdit_Click:
Exit Sub

Err_cmdPtasEdit_Click:
MsgBox Err.Description
Resume Exit_cmdPtasEdit_Click

End Sub
I want this code to open the frmPtasEdit form at the same record that is being displayed on the frmHostNationViewProcedure when the cmd button cmdPtasEdit is clicked.

The frmPtasView uses qryPtasView for the fields on the subform, but I don’t understand how the query qryPtasView is preventing new additions. I am also unsure of what you mean by remove some of the tables and display them as subs of the sub or change the joins.

I feel like I am getting very close to getting this figured out.

In case I am being as clear as mud, I can send you my latest attempt at this project, if you have the time.

Thanks,
Mike
 
OK I noticed when downloading even the zip that your database size seemed large for the limited data and lack of graphics within the database, I compiled and saved all modules which brought up two errors nothing serious fields you've re-named, I then compacted the database which brought the file size down from 7meg to 1.9 much better. It's worth doing daily esp if your continually making design changes it's also worth importing the whole lot into a new blank database and repeating the process from time to time if making a large number of changes.
 
Rich,
Thanks for the help. I was wondering why my database was so large, I never thought there was that much data. Now I know.
The code works great.

How do I get the subform to show the newly added record without closing and opening the form. I tried to use the requery on timer event, but that does not work great. The data is updated but the record counter on the navigation bar flashes when the requery is done and record one is displayed.

Mike
 

Users who are viewing this thread

Back
Top Bottom