Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find a form from module code

Status
Not open for further replies.

Albano

Instructor
Dec 11, 2000
221
PT
Hi I have this sub called in a module:

Sub getAcessos(aTipoUser As Integer, aObjecto As String)
Dim RSAcessos As DAO.Recordset
Dim Dbs As Database
Dim StrSql As String
Dim tipoAcesso As Integer
Dim tObj As Form

Set tObj = Forms(aObjecto)

'BD a ser utilizada é a actual
Set Dbs = CurrentDb()

StrSql = "select * from acessos where TipoUtilizador=" & aTipoUser & " and objecto='" & aObjecto & "'"

Set RSAcessos = Dbs.OpenRecordset(StrSql, dbOpenSnapshot, dbReadOnly)
If Not RSAcessos.EOF Then
tipoAcesso = RSAcessos("tipoAcesso")
Else
tipoAcesso = 0
End If

Select Case tipoAcesso
Case 1 'Leitura
tObj.AllowEdits = False
tObj.AllowAdditions = False
tObj.AllowDeletions = False
tObj.ShortcutMenu = False
Case 2 'Leitura/Escrita
tObj.AllowEdits = True
tObj.AllowAdditions = True
tObj.AllowDeletions = True
tObj.ShortcutMenu = False
Case 3 'Acesso Negado
MsgBox ("Não tem permissões para aceder a este formulário!, contacte o administrador!")
DoCmd.Close
Case 4 'Acesso Total
tObj.AllowEdits = True
tObj.AllowAdditions = True
tObj.AllowDeletions = True
tObj.ShortcutMenu = True
Case Else 'não tem acesso
MsgBox ("Não tem permissões para aceder a este formulário!, contacte o administrador!")
DoCmd.Close
End Select


RSAcessos.Close

Set Dbs = Nothing
End Sub

when I trie do call the sub in a subform it give a Run.time error '2450', can't find the form... in the line "Set tObj = Forms(aObjecto)" of the sub.

Can someane help.

Thanks.
 
Is the object in aObjecto a subform? If so, you will need to refer to the parent form, then the subform.
 
the object in aObjecto is a form. I have a mainForm (menu) and inside I have a subform, and when a button is clicked the SourceObject of the subform is changed to a form.

The problem is that the sub inside the nodule dont't reconize the form when is called from the subform.

MainForm (have buttons)
.Subform (is where we view the forms by chaging the SourceObject)
.Forms (the actual form with fileds)
 
What I mean is:

module1-> have a sub x() that chage some properties of agiven form
form1 ->call the sub x() and pass the form name like me.name
mainForm ->have a subform1 liked to the form1 by the sourceObject

the problem is that when the sub is called the form1 name isn't reconized.

I alreay tried the solution you give but doesn't work.

 
If I call your code from a main form with me form name,

[tt]Set tObj = Forms(aObjecto)[/tt]

Will work as Me.Name is part of the forms collection. However, if I call it from a subform, Me.Name is not part of the forms collection. To refer to the form contained by a subform control, I must say:

[tt]Set tObj = Forms!MainForm![Subform Control Name].Form
[/tt]

The subform control name is the name of the subform control on the main form, which is often the same as the name of the form contained by this control, but not always.
 
For me, a simpler way is to pass the form object as parameter instead of the form name ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top