Full Version: VBA Linkmasterfields Error 2101
UtterAccess Forums > Microsoft® Access > Access Forms
ry94080
Hi all,

I have a form that has a drop down box which should change the SourceObject of a subform. However when I try to re-assign the LinkMasterFields, I get this error:

2101 is the error code for this event. The setting you entered isn't valid for this property.

Here is my code
CODE
Private Sub cboSelection_AfterUpdate()

Select Case Me.cboSelection.Value

    Case "Refrigeration"
        LoadRefrigerationForm
    Case "Incubation"
        LoadIncubationForm
End Select

End Sub


Sub LoadRefrigerationForm()
On Error GoTo LoadRefrigerationForm_Err

Me.Detail.BackColor = RGB(165, 219, 175)

Me.sfrmDeviceToCIDs.SourceObject = ""
Me.sfrmDeviceToCIDs.LinkMasterFields = ""
Me.sfrmDeviceToCIDs.LinkChildFields = ""


Me.Requery

Me.cboDevices.RowSource = "SELECT tblRefrigerators.Refrigerator FROM tblRefrigerators;"
Me.cboDevices.ControlSource = "Refrigerator"
Me.cboRack.RowSource = "SELECT tblRefrigeratorRacks.Rack FROM tblRefrigeratorRacks;"
Me.cboRack.ControlSource = "RefrigeratorRack"

Me.RecordSource = "SELECT tblRefrigerations.RefrigerationsID, tblRefrigerations.Refrigerator, tblRefrigerations.RefrigeratorRack, tblRefrigerations.StartDateTime, tblRefrigerations.EndDateTime FROM tblRefrigerations WHERE (((tblRefrigerations.EndDateTime) Is Null));"

Me.Requery



Me.sfrmDeviceToCIDs.SourceObject = "frmRefrigerationToCID"
Me.sfrmDeviceToCIDs.LinkMasterFields = "RefrigerationsID"
Me.sfrmDeviceToCIDs.LinkChildFields = "RefrigerationID"









'RecordCount

'DoCmd.GoToRecord , , acNewRec

Exit Sub
LoadRefrigerationForm_Err:
MsgBox Err.Number & " is the error code for this event. " & Err.Description
End Sub

Sub LoadIncubationForm()
On Error GoTo LoadIncubationForm_Err

Me.Detail.BackColor = RGB(243, 227, 231)


Me.sfrmDeviceToCIDs.LinkMasterFields = ""
Me.sfrmDeviceToCIDs.LinkChildFields = ""
Me.sfrmDeviceToCIDs.SourceObject = ""

Me.Requery

Me.cboDevices.RowSource = "SELECT tblIncubators.Incubator FROM tblIncubators;"
Me.cboDevices.ControlSource = "Incubator"
Me.cboRack.RowSource = "SELECT tblRacks.Rack FROM tblRacks;"
Me.cboRack.ControlSource = "Rack"

Me.RecordSource = "SELECT tblIncubations.IncubationsID, tblIncubations.Incubator, tblIncubations.Rack, tblIncubations.StartDateTime, tblIncubations.EndDateTime FROM tblIncubations WHERE (((tblIncubations.EndDateTime) Is Null)); "


Me.Requery


Me.sfrmDeviceToCIDs.SourceObject = "frmIncubationsToCID"
Me.sfrmDeviceToCIDs.LinkMasterFields = "IncubationsID"
Me.sfrmDeviceToCIDs.LinkChildFields = "IncubationID"







'RecordCount

'DoCmd.GoToRecord , , acNewRec

Exit Sub
LoadIncubationForm_Err:
If Err.Number = 2101 Then
    Resume Next
Else
    MsgBox Err.Number & " is the error code for this event. " & Err.Description
End If
End Sub
theDBguy
Hi,

Can you tell which line is causing the error?
pere_de_chipstick
IIRC, you must always have the same number of linked fields in both the master and child properties of the sub form control when you change them using VBA.

If you change one or other to or from a ZLS ("") then this rule is broken and the code will fail.

I don't use the master and child link properties, in part, for this reason, but prefer to put a link to a control on the master form as a criteria in the sub forms underlying query, or to use the sub forms filter property.

hth
projecttoday
It looks like you're trying to switch between refrigeration and incubation. If you put a tab control on the main form and put the 2 subforms each on one of the tabs permanently the user can select whichever tab he needs and you don't need any code at all.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.