- Local time
- Yesterday, 16:16
- Joined
- Oct 29, 2018
- Messages
- 22,520
Yes, you can combine the loops by using either an Else or ElseIf branch, or my favorite, Select Case statement.This code opens the form in the state I want to see it. I am wondering if there is a more succinct way to code it.......can the Loops be combined somehow?
Code:Private Sub Form_Load() Dim rs As DAO.Recordset If Not Trim(Me.OpenArgs & " ") = "" Then 'See if record exists Set rs = Me.Recordset 'MsgBox Me.OpenArgs rs.FindFirst "InspectionEvent_FK = " & CLng(Me.OpenArgs) If rs.NoMatch Then 'it does not exist so you need to create it DoCmd.GoToRecord acDataForm, Me.Name, acNewRec Me.InspectionEvent_FK = Me.OpenArgs Me.txtFinalProd_FK = intFinalProdID Me.NavigationButtons = False Me.cmdSaveLineStop.Enabled = False For Each ctl In Me.Controls If ctl.Tag = "required" Then ctl.Enabled = False End If Next For Each ctl In Me.Controls If ctl.Tag = "secondary" Then ctl.Enabled = False End If Next Me.cboLine1Workstation.Enabled = True End If Else If IsNull(Me.OpenArgs) Then Me.Filter = "LineStopBegin Is Not Null AND LineStopEnd Is Null" Me.FilterOn = True Me.NavigationButtons = True End If End If End Sub
Edit: Wait a minute... You're disabling all the controls in your code! If so, you should be able to do something like:
Code:
If ctl.Tag = "required" OR ctl.Tag = "secondary" Then