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!

Convert String to command button

Status
Not open for further replies.

Albano

Instructor
Dec 11, 2000
221
PT
Hi,

Thirs any whay of converting a string to command button object.

I have this function, and i need to use the string paramenter aButton as a command button:

Sub desactivaMenu(aTipoUser As Integer, aObjecto As String, aButton As String)
Dim RSAcessos As DAO.Recordset
Dim Dbs As Database
Dim StrSql As String
Dim tipoAcesso As Integer
Dim tObj As Form
Dim tCmd As Variant -> the problem is hear

Set tCmd = aBotao -> the problem is hear

Set tObj = Forms!ecranPrincipal.Form

'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

If tipoAcesso = 3 And tObj.Name = "ecranPrincipal" Then
tObj.tCmd.Enabled = False
Forms!ecranPrincipal![central].SourceObject = "F_vazio"
End If

RSAcessos.Close

Set Dbs = Nothing
End Sub

Thanks

Albano
 


Hi,

A STRING is not an Object.

Is this string IN an Object like Lable or Textbox? Then in some cases the Object may have a method that can be used like a Button_Click

Skip,

[glasses] [red][/red]
[tongue]
 

Do you mean you want the string to become the CAPTION on a command button? Something like...
Me.cmdButton.Caption = "your String"


Randy
 
Hi,

No, what I whant is to pass a button name as a string to a sub, and the use the string as a object to change de enabled propertie of the button.
 
As far as I recall, you can say:

[tt]Set tObj = Forms!ecranPrincipal.Form
Set tCmd = tObj.Controls(aBotao)[/tt]


 
Maybe this:
Code:
[blue]    Dim tObj As Form
    Dim tCmd As Control
   
    Set tObj = Forms!ecranPrincipal.Form
    Set [purple][b]tCmd[/b][/purple] = tobject!aBotao
    [green]'
    ' your code
    '[/green]
    If tipoAcesso = 3 And tObj.Name = "ecranPrincipal" Then
      [purple][b]tCmd[/b][/purple].Enabled = False
     Forms!ecranPrincipal![central].SourceObject = "F_vazio"
   End If
    [green]'
    ' your code
    '[/green][/blue]

Calvin.gif
See Ya! . . . . . .
 
It works with

Dim tCmd As Object

Set tObj = Forms!ecranPrincipal.Form
Set tCmd = tObj.Controls(aBotao)

thanks all
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top