Home > database >  access a specific field within a query that is part of a subform
access a specific field within a query that is part of a subform

Time:06-01

I am trying to get an understanding of what the syntax would be to access a specific field within a query that makes up a subform within another form. Form > SubForm/Query > Field

The field I am trying to get access to a field called Berthed that operates as a Boolean field. Either the vessel is present or it is absent.

This is what I was trying and it does not work.

Me.Boat_Move_Prior_Week.SourceObject.berthed

In this case here is the breakdown

Me = current form

Boat_Move_Prior_Week = query

Berthed = field I am trying to access through the VBA

My final goal will be to create an If statement, that upon requery of the Form, will look at the Berthed field, and if the field is checked (vessel is present) do nothing, but if the field is unchecked (vessel is not present) then remove the vessel from the query.

CodePudding user response:

To reach the field (on the subform) bound to the field berthed, this is the syntax (assuming the textbox on the subform also is named berthed):

IsBerthed = Me!NameOfSubformControl.Form!berthed.Value

CodePudding user response:

Here an amazing guide to know how to deal with controls in main form and subforms:

Link

CodePudding user response:

Aside from my syntax issues I should have been using False for the value. Thanks to the two posters above for getting me in the right direction.

If Me.Boat_Move_Prior_Week.Form!BERTHED.value = False Then
        Me.Boat_Move_Prior_Week.SourceObject = ""
End If
  • Related