I tried something similar to that already as well to the same effect, I even put in debug.print messages between individual lines of code and it's progressing through my commands just fine just doesn't seem to execute them. I'm not even getting any error messages
Just for the sake of ruling out a problem with my form frm_edit_courts I created a brand new form with one control on it named fld_court_name. There is no code whatsoever attached to this form and ran this:
Code:
Dim frm As Form
Dim fld As TextBox
If DCount("*", "Tbl_Courts") = 0 Then
DoCmd.OpenForm "frm_edit_courts"
End If
If SysCmd(acSysCmdGetObjectState, acForm, "Frm_Edit_courts") <> 0 Then
Debug.Print "IN HERE"
Forms!frm_edit_courts.Form.SetFocus
Debug.Print "focus should be set to form frm_edit_courts"
Forms!frm_edit_courts!fld_Court_Name.SetFocus
Debug.Print "focus should be set to form frm_edit_courts field fld_court_name"
End If
this code is printing all three debug.print messages, I am getting no errors but the form is still opening in the background.
I know pop up would work but I really do not want to do that for this database I just can't figure out why the setfocus isn't working, nor can I figure out why docmd.openform is behaving differently when it's inside a set of code (in this case my record count check) vs. just being a simple docmd.openform that's no conditional.