Question set focus specific form

zeeroone

New member
Local time
Today, 15:30
Joined
Nov 11, 2011
Messages
8
Hi,

I'm new in MS access and i have a problem with regards with the setfocus of certain form. i have a command button that will open several forms and once open i want to setfocus it in "Purchase Requisition" form. please see code below

Private Sub Login_Click()
Dim Password As Variant
Password = DLookup("Password", "Users", "UserID = '" & Me.txtUserID & "' ")

If Nz(Password, "") = Me.txtpassword Then
DoCmd.Close

DoCmd.OpenForm "Purchase Requisition"
DoCmd.OpenForm "Purchase Order"
DoCmd.OpenForm "Supplier Information"
DoCmd.OpenForm "Archive"
DoCmd.OpenForm "Others"

Else
MsgBox "Incorrect user ID or password"
End If

End Sub

hope you could help me on this one

thanks in advance
 
Try the following;
Code:
Private Sub Login_Click()
Dim Password As Variant
Password = DLookup("Password", "Users", "UserID = '" & Me.txtUserID & "' ")

If Nz(Password, "") = Me.txtpassword Then
DoCmd.Close

DoCmd.OpenForm "Purchase Requisition"
DoCmd.OpenForm "Purchase Order"
DoCmd.OpenForm "Supplier Information"
DoCmd.OpenForm "Archive"
DoCmd.OpenForm "Others"
[COLOR="Red"]
Forms!"Purchase Requisition"!YourControlName.SetFocus[/COLOR]

Else
MsgBox "Incorrect user ID or password"
End If

End Sub

Book mark this link for future reference.
 
Also it will simplify things if you avoid using spaces and other special characters in your object and control names, limit yourself to alpha and numeric characters and the under score.

Consider also a naming protocol along the lines of FRM_FormName, TBL_TableName, QRY_QueryName etc.
 
thanks for the reply John, I still encounter some error

Compile Error:
Expected:end of statement
 
The answer to that problem, as to any problem, is 42.

If you want anything more specific, then remember that we do not have remote vision, and provide the code and indicate the failing line.
 
Hi Spikepl,

my apology, Please see below


Private Sub Login_Click()
Dim Password As Variant
Password = DLookup("Password", "Users", "UserID = '" & Me.txtUserID & "' ")

If Nz(Password, "") = Me.txtpassword Then
DoCmd.Close

DoCmd.OpenForm "Purchase Requisition"
DoCmd.OpenForm "Purchase Order"
DoCmd.OpenForm "Supplier Information"
DoCmd.OpenForm "Archive"
DoCmd.OpenForm "Others"

Forms! "Purchase Requisition"!T no.SetFocus

Else
MsgBox "Incorrect user ID or password"
End If

End Sub
 
Forms! [Purchase Requisition]!Tno.SetFocus

and as John wrote, avoid form/table/field names with spaces.
 
thanks again, how about this error

Private Sub Command7_Click()
Dim strPasswd
strPasswd = InputBox("Enter Password", "Restricted Form")
'Check to see if there is any entry made to input box, or if
'cancel button is pressed. If no entry made then exit sub.
If strPasswd = "" Or strPasswd = Empty Then
MsgBox "No Input Provided", vbInformation, "Required Data"
Exit Sub
End If
'If correct password is entered open Delivery Monitoring form
'If incorrect password entered give message and exit sub

If strPasswd = "general" Then
DoCmd.Close "login"

DoCmd.OpenForm "Delivery Monitoring", acNormal

Exit Sub
Else
MsgBox "Sorry, you do not have access to this form", _
vbOKOnly, "Important Information"

Exit Sub


End If

End Sub
 
What error? If this is a syntax error then look up DoCmd.Close in the documentation.
 

Users who are viewing this thread

Back
Top Bottom