You just need to add the code within code to to the onclose event like this:
Private Sub closeFrmswitchlogin_Click()
On Error GoTo Err_closeFrmswitchlogin_Click
Dim db As Database
Dim prop As DAO.Property
Set db = CurrentDb
Set prp = db.CreateProperty("allowbypasskey", dbBoolean, False)...