A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Testing Subform Records to make button visible



 
 
Thread Tools Display Modes
  #1  
Old April 2nd, 2010, 09:18 AM posted to microsoft.public.access.forms
Jochen
external usenet poster
 
Posts: 18
Default Testing Subform Records to make button visible

I have a form with a subform
The subform can contain multiple records.
I want to test all the records in the subform
If the yes/no field "appointment" is true in one or more records a button
should be made visible on the main form.

How do I test the records in a subform?
  #2  
Old April 2nd, 2010, 01:28 PM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Testing Subform Records to make button visible

Use the Current event of the main form, to DLookup() the primary key value
of the related table in the subform where the yes/no field is true.

This kind of thing
Private Sub Form_Current()
Dim strWhere As String
Dim bAppointmentsExist as Boolean
If Not Me.NewRecord Then
strWhere = "(Appointment False) AND (ForeignID = " & Me.MainID & ")"
bAppointmentsExist = Not IsNull(DLookup("SubID", "Table2", strWhere))
End If
With Me.Command1
If .Enabled bAppointmentsExist Then
.Enabled = bAppointmentsExist
End If
End With
End Sub

Add error handling, in case the button has focus when you move record.

You may also want to use the subform's Form_AfterUpdate and
Form_AfterDelConfirm events to keep the button's state correct as records
are added to, removed from, and edited in the subform.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"Jochen" wrote in message
...
I have a form with a subform
The subform can contain multiple records.
I want to test all the records in the subform
If the yes/no field "appointment" is true in one or more records a button
should be made visible on the main form.

How do I test the records in a subform?


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:31 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.