hide command buttons if field is populated

cdnicholson

cassandra
Local time
Today, 06:47
Joined
Jun 22, 2009
Messages
9
My main form, frmIssue, has command buttons to a open child form, frmIssueAuthoring, for data entry. When the child form is closed and the user returns to the main form, I don't want the command button that opened the frmIssueAuthoring to be visible anymore, since the fields one the form have been populated. I expect it will look something like this:

If frmIssueAuthoring![IssueKey] Is Null Then
Me![cmdAddIssueAuthoring].Visible = True
Else
Me![cmdAddIssueAuthoring].Visible = False
End If

What am I missing? Where do I put this code on the main form?

Thanks in advance!
 
Try:

If IsNull(forms!frmIssueAuthoring![IssueKey] Then

Or:

If forms!frmIssueAuthoring![IssueKey] & "" = "" Then
 
Thanks. This worked great when looking for null values within the same form. However, I can't get it to work looking for null values in a subform.

Here is the code that IS WORKING for a label in the same form:

If IsNull(Me![txtMigratedReferences]) Then
Me![lblMigratedReferences].Visible = False
Else
Me![lblMigratedReferences].Visible = True
End If

Here is the code that I CAN'T get to work looking for a null value in a subform:

If IsNull(Forms!fsubIssueAuthoring![IssueKey]) Then
Me![cmdAddIssueAuthoring].Visible = True
Else
Me![cmdAddIssueAuthoring].Visible = False
End If

I keep getting the run-time error: Executive Issue Management can't find the form 'fsubIssueAuthoring' referred to in a macro or expression or Visual Basic Code.

What am I missing?

Thanks for any help!
 
Subform syntax is different. You cannot use the same syntax as on a standalone form. With subforms you have two parts - a container which holds the subform on the main form and the subform itself. So for code you need to refer to the container and not the subform and then if you want to refer to something on the subform you need to use .Form. before the object, or method, you want to refer to on the subform.

so for example, if you have a subform named Subform1 and you have the container on the main form (frmMain) which is named Child122 for example and you want to refer to a text box (named txtTest) on the subform then you would need to use:

Forms!frmMain.Child122.Form.txtTest

sometimes the container and the subform are named the same, which is okay, and so then using the container name, makes it look like you use the subform name and that is what confuses people.

If the container was named Subform1 as well as the subform being named Subform1 then you could use

Forms!frmMain.Subform1.Form.txtTest

And then if the code is on the main form then you would use the ME keyword:

Me.Child122.Form.txtTest

Does that help?
 
Excellent!! Thanks so much. It took a bit for me to find out the "container" name, but it's working great now.

Thanks for taking the time to help out!
 
Excellent!! Thanks so much. It took a bit for me to find out the "container" name, but it's working great now.

Thanks for taking the time to help out!
Happy to have been of service :)
 
not quite there...

My command buttons are always hidden now - regardless of whether the subform has a related record or not. Is the code looking at the data in the related subform (or container) or all data in the table the subform is based on? If so, then there will already be a record with data in the txtIssueKey field. Maybe what I really want is if the value of txtIssueKey on the subform matches the value of txtIssueKey on the main form?
 
Yeah, it is probably based on the first record in the subform. You may want to check the subform RECORD COUNT to see if it contains more than 0 records and then you would also want the code in the main form's On Current event so it would change as you move between records. You might take what you have and put it in the On Current event of the main form and see if it does it without changing the way you have it.
 
The table the subform is based on has over 300 records. Putting the code on the On Current event didn't fix it.
 
You can test for the count on the subform by using

Code:
Dim rst As DAO.Recordset
Set rst = Me.YourSubformContainerHere.Form.RecordsetClone
 
If rst.RecordCount > 0 Then 
' DO YOUR STUFF HERE
End If
 
rst.Close
Set rst = Nothing
 

Users who are viewing this thread

Back
Top Bottom