Open Form based on Field in a hidden form

R

Ryis

Hello,

I am trying to open a form based on what is in a field on a hidden form but
I cannot seem to correct it. I used the same coding principle for opening
the current form using the Me. but I am having trouble referencing the data
in the hidden form. This is what i have.

Private Sub ADMIN_MENU_Click()

If Forms!SIGNIN!LOGINBACK_subform!PERMISSION_LEVEL <> "SUPER ADMIN" Or
IsNull (Forms!SIGNIN!LOGINBACK_subform!PERMISSION_LEVEL) Then
MsgBox "YOU DO NOT HAVE AUTHORIZATION!", vbExclamation, "Try Again"

Else

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "ADMIN MENU"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Me.Visible = True


End If

ExitPoint:
Exit Sub

ErrorPoint:
MsgBox "The following error has occurred: " _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.DESCRIPTION _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Sub

thanks for your help in advanced
 
D

Dan Knight

Rvis,
There are a couple of questions that I see:
1) Where is the code you posted located - what calls the code? I'm assuming
"Admin_Menu" is a cmd button or control that is clicked to cal the code. and
I'm assuming this control is on your "current" form.

2) Your "Docmd.openform" line opens a form called "AdminMenu", which I'm
assuming is a different form from your "current" form.

3) Your "Me.Visible = True" line would make visible the "current" form. If
you're wanting this line to make visible the AdminMenu form, you'd have to
reference that form or change the line to Me.Visible = false

4) Also, your Docmd.OpenForm line references a stLinkCriteria yet I don't
see where you define the stLinkCriteria string.

Dan Knight
 
J

Jeanette Cunningham

Hi Ryis
there is a special syntax to use when getting a value from a subform.
A subform on a form always sits inside a subform control.
The subform control sometimes has the same name as the subform and sometimes
it doesn't.

To refer to a control on a subform you need to use the name of the subform
control.
Like this:

Forms![NameOfSubformControl].Form.PERMISSION_LEVEL


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
R

Ryis

Hi Dan,

1) Where is the code you posted located - what calls the code? I'm assuming
"Admin_Menu" is a cmd button or control that is clicked to cal the code. and
I'm assuming this control is on your "current" form.

-Admin_menu is athe cmd button on my current form

2) Your "Docmd.openform" line opens a form called "AdminMenu", which I'm
assuming is a different form from your "current" form.

YES

3) Your "Me.Visible = True" line would make visible the "current" form. If
you're wanting this line to make visible the AdminMenu form, you'd have to
reference that form or change the line to Me.Visible = false

I have removed this line and insert a close command

4) Also, your Docmd.OpenForm line references a stLinkCriteria yet I don't
see where you define the stLinkCriteria string.

I have not set the criteria yet....probably set to normal

Where I am having the trouble is referencing the field on a sub form of a
hidden form in the following line.

If Forms!SIGNIN!LOGINBACK_subform!PERMISSION_LEVEL <> "SUPER ADMIN" Or
IsNull(Forms!SIGNIN!LOGINBACK_subform!PERMISSION_LEVEL) Then

If the field of LOGINBACK_subform!PERMISSION_LEVEL equals SUPER ADMIN then i
want the code to open the form ADMIN MENU. if not display the message box.
 
N

NKTower

put this at the appropriate location...

Dim frm_Login As Form
Dim sfm_Hidden As Form
Dim ctrl_Authorization As Control

If Not CurrentProject.AllForms("Login").IsLoaded Then
Debug.Print "Login form isn't open?"
' take corrective action
End If
Set frm_Login = Forms![Login].Form
Set sfm_Hidden = frm_Login.Form!sfm_Hidden.Form
Set ctrl_Authorization = sfm_Hidden.Controls("txt_Authorization")
If ctrl_Authorization & "" = "SUPERADMIN" Then
Debug.Print "do something good"
Else
Debug.Print "do something bad"
End If

' release the objects that were created
Set ctrl_Authorizatin = Nothing
Set sfm_Idden = Nothing
Set frm_Login = Nothing
 
R

Ryis

Hi Jeanette,

still having no luck, can't seem to get the coding right this is what i
interpret from your last message.

I believe that my subform control is "LOGINBACK subform"

My hidden form is "SIGNIN"
My subform on the hidden form is "LOGINBACK subform"(datasheet)
and the field on the datasheet that I want to reference is "PERMISSION LEVEL"

any help would be appreciated..

Thanks

Jeanette Cunningham said:
Hi Ryis
there is a special syntax to use when getting a value from a subform.
A subform on a form always sits inside a subform control.
The subform control sometimes has the same name as the subform and sometimes
it doesn't.

To refer to a control on a subform you need to use the name of the subform
control.
Like this:

Forms![NameOfSubformControl].Form.PERMISSION_LEVEL


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Ryis said:
Hello,

I am trying to open a form based on what is in a field on a hidden form
but
I cannot seem to correct it. I used the same coding principle for opening
the current form using the Me. but I am having trouble referencing the
data
in the hidden form. This is what i have.

Private Sub ADMIN_MENU_Click()

If Forms!SIGNIN!LOGINBACK_subform!PERMISSION_LEVEL <> "SUPER ADMIN" Or
IsNull (Forms!SIGNIN!LOGINBACK_subform!PERMISSION_LEVEL) Then
MsgBox "YOU DO NOT HAVE AUTHORIZATION!", vbExclamation, "Try Again"

Else

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "ADMIN MENU"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Me.Visible = True


End If

ExitPoint:
Exit Sub

ErrorPoint:
MsgBox "The following error has occurred: " _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.DESCRIPTION _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Sub

thanks for your help in advanced
 
J

Jeanette Cunningham

You can check the name of the subform control by opening the main form in
design view.
Click only once on the subform, and the subform control will be selected,
check its name on the property dialog | Other tab.
If the name of the subform control has 2 words, you will need brackets
around it.

You can try it like this:

Forms!SIGNIN!LOGINBACK_subform.Form!PERMISSION_LEVEL

If you are still having problems, you may need to look at how you are
choosing the correct record on the hidden subform.
Do you know for sure that you are comparing with the correct subform
permission level?

This site explains the syntax for forms and subforms
http://www.mvps.org/access/forms/frm0031.htm


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Ryis said:
Hi Jeanette,

still having no luck, can't seem to get the coding right this is what i
interpret from your last message.

I believe that my subform control is "LOGINBACK subform"

My hidden form is "SIGNIN"
My subform on the hidden form is "LOGINBACK subform"(datasheet)
and the field on the datasheet that I want to reference is "PERMISSION
LEVEL"

any help would be appreciated..

Thanks

Jeanette Cunningham said:
Hi Ryis
there is a special syntax to use when getting a value from a subform.
A subform on a form always sits inside a subform control.
The subform control sometimes has the same name as the subform and
sometimes
it doesn't.

To refer to a control on a subform you need to use the name of the
subform
control.
Like this:

Forms![NameOfSubformControl].Form.PERMISSION_LEVEL


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Ryis said:
Hello,

I am trying to open a form based on what is in a field on a hidden form
but
I cannot seem to correct it. I used the same coding principle for
opening
the current form using the Me. but I am having trouble referencing the
data
in the hidden form. This is what i have.

Private Sub ADMIN_MENU_Click()

If Forms!SIGNIN!LOGINBACK_subform!PERMISSION_LEVEL <> "SUPER ADMIN" Or
IsNull (Forms!SIGNIN!LOGINBACK_subform!PERMISSION_LEVEL) Then
MsgBox "YOU DO NOT HAVE AUTHORIZATION!", vbExclamation, "Try Again"

Else

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "ADMIN MENU"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Me.Visible = True


End If

ExitPoint:
Exit Sub

ErrorPoint:
MsgBox "The following error has occurred: " _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.DESCRIPTION _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Sub

thanks for your help in advanced
 
R

Ryis

Thanks Jeanette,

for the link to the site about forms and subforms..as it turns out I had a
"!" where I needed a ".", everything is working great!! thanks for your
time, much appreciated

Ryan

Jeanette Cunningham said:
You can check the name of the subform control by opening the main form in
design view.
Click only once on the subform, and the subform control will be selected,
check its name on the property dialog | Other tab.
If the name of the subform control has 2 words, you will need brackets
around it.

You can try it like this:

Forms!SIGNIN!LOGINBACK_subform.Form!PERMISSION_LEVEL

If you are still having problems, you may need to look at how you are
choosing the correct record on the hidden subform.
Do you know for sure that you are comparing with the correct subform
permission level?

This site explains the syntax for forms and subforms
http://www.mvps.org/access/forms/frm0031.htm


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Ryis said:
Hi Jeanette,

still having no luck, can't seem to get the coding right this is what i
interpret from your last message.

I believe that my subform control is "LOGINBACK subform"

My hidden form is "SIGNIN"
My subform on the hidden form is "LOGINBACK subform"(datasheet)
and the field on the datasheet that I want to reference is "PERMISSION
LEVEL"

any help would be appreciated..

Thanks

Jeanette Cunningham said:
Hi Ryis
there is a special syntax to use when getting a value from a subform.
A subform on a form always sits inside a subform control.
The subform control sometimes has the same name as the subform and
sometimes
it doesn't.

To refer to a control on a subform you need to use the name of the
subform
control.
Like this:

Forms![NameOfSubformControl].Form.PERMISSION_LEVEL


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Hello,

I am trying to open a form based on what is in a field on a hidden form
but
I cannot seem to correct it. I used the same coding principle for
opening
the current form using the Me. but I am having trouble referencing the
data
in the hidden form. This is what i have.

Private Sub ADMIN_MENU_Click()

If Forms!SIGNIN!LOGINBACK_subform!PERMISSION_LEVEL <> "SUPER ADMIN" Or
IsNull (Forms!SIGNIN!LOGINBACK_subform!PERMISSION_LEVEL) Then
MsgBox "YOU DO NOT HAVE AUTHORIZATION!", vbExclamation, "Try Again"

Else

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "ADMIN MENU"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Me.Visible = True


End If

ExitPoint:
Exit Sub

ErrorPoint:
MsgBox "The following error has occurred: " _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.DESCRIPTION _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Sub

thanks for your help in advanced
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top