This is the code for a form that I have setup to open when a database is open. As far as the second part, I really don't understand what you are wanting. Sorry.
Private Sub cmdEnter_Click()
Dim db As DATABASE
Dim rs As Recordset
Dim frm As Form, ctl As Control, ctl2 As Control
Dim varResult As Variant
Dim varResult2 As Variant
Dim sLogin As String
Dim sPassword As String
On Error GoTo cmdEnter_Click_Error
Set db = CurrentDb
Set rs = db.OpenRecordset("tblLogin"

Set frm = Forms!frmLogin
Set ctl = frm!txtLogin
Set ctl2 = frm!txtPassword
'This will return "" or Empty if txtLogin is blank
varResult = Nz(ctl.Value)
varResult2 = Nz(ctl2.Value)
'If either field is blank it will start over, if both have values then it will continue
If (varResult = "" Or varResult2 = ""

= True Then
MsgBox "You did not fill this form out correctly. Plese fill in all fields....", , "Missing Info"
ctl = ""
ctl2 = ""
ctl.SetFocus
Exit Sub
Else
'Everything looks fine so continue
sLogin = Me!txtLogin.Value
sPassword = Me!txtPassword.Value
End If
rs.MoveFirst
Do Until rs.EOF
If sLogin = rs!txtLogin Then
If sPassword = rs!txtPassword Then
MsgBox "You are now logged in", , "Logged In"
DoCmd.Close acForm, "frmLogin"
DoCmd.OpenForm "frmMain"
Exit Sub
Else
MsgBox "You have the login in correct but you did not supply the correct password. Please try again", , "Wrong Password"
Me!txtPassword.SetFocus
Exit Sub
End If
Else
rs.MoveNext
End If
Loop
MsgBox "This Login name is unrecognized"
rs.Close
Me.txtLogin.SetFocus
cmdEnter_Click_Exit:
Exit Sub
cmdEnter_Click_Error:
'If Err.Number = 94 Then
'Me!txtLogin.SetFocus
'Else
MsgBox Err.Number & ": " & Err.Description
'End If
Resume cmdEnter_Click_Exit
End Sub