Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

My project has a form with tabs, each tab displaying data from a different table based on the current record (I will call the main form's record the client) selected in the main form. If there is data present in the child table associated with that client, then show the data. If there isn't, I have a text field in my form header to say there are no records, with a link to open up a form for adding data to said child table. The form header also contains column headers for my continuous forms.

Now, if on the child form, I have Allow Additions turned off, then if the child table is empty for that client, it shows no data and the form_current or form_load methods do not seem to run, which is where I had code for hiding the column headers and unhiding my "No records" status/header text box, and vice-versa if there is data in the child form. If I turn Allow Additions on, then my code runs to hide the columns and show the status text box, but when there is data available in the table it shows the "new row" at the end of my results. I do not want the new row there.

So I can either turn on Allow Additions, have my code work, and it shows an extra new row, or I can turn off Allow Additions, my code breaks, but I don't have the extra new.

I tried to do this:

If Me.NewRecord Then
    Me.field1.Visible = False
End If

but this produces undesired results; it doesn't hide the new row until I select it, then it hides all fields. I know that is how it should work, its just not the result I want .

share|improve this question

1 Answer

You have a tab page which contains a subform control. It can also contain other controls. Add a label for "No data" and a command button for "Add records". Position them behind the subform control. (Look for "Bring to Front" and "Send to Back" on the "Arrange" section of the ribbon.)

The in the main form's On Current event, set the subform control's .Visible property based on whether or not the subform will contain any records.

If the subform Link Master/Child property is a common field named client_id, On Current might be something like this ...

Me.SubformControlName.Visible = _
    (DCount("*", "ClientDetails", "client_id =" & Me.txtClient_id) > 0)

Assuming that works, you can leave allow additions off for the subform to suppress the new row. And you wouldn't need to bother with visibility of the subform headers.

But one point puzzles me. Your description sounds like you want the "add records" button available only when the subform contains no records. If you also want to make it available to add more records when the subform already contains some, re-position it so it's not behind the subform control.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.