PDA

View Full Version : Code does not pull data correctly at login



marreco
03-16-2013, 04:59 PM
Hi.

In worksheet "Users" I have a column "A" for Users and column "B" for Password.

happens that the code I'm using is not working properly.

he takes only the second line, I need you to get all the rows filled with data from Column "A" and "B"

thank you!

Doug Robbins
03-16-2013, 06:51 PM
Use:

Private Sub cmdEntrar_Click()
Dim blnvalid As Boolean
If txtlogin = "" Then
MsgBox "Digite o nome do usuário !"
Exit Sub
txtlogin.SetFocus
Else
If txtsenha = "" Then
MsgBox "Digite a senha do usuário !"
Exit Sub
txtsenha.SetFocus
End If
End If
blnvalid = False
With Plan8.Range("A1")
For i = 1 To .CurrentRegion.Rows.Count - 1
If Trim(.Offset(i, 0)) = txtlogin And Trim(.Offset(i, 1)) = txtsenha Then
blnvalid = True
Exit For
End If
MsgBox blnvalid
Next i
End With

If blnvalid = False Then
MsgBox "A senha năo confere !!"
Exit Sub
Else
MsgBox "Seja Bem Vindo " & txtlogin
lin = 2
col = 1
While (Plan9.Cells(lin, col) <> "")
lin = lin + 1
Wend
Plan9.Cells(lin, 1) = txtlogin.Value
Plan9.Cells(lin, 2) = txtsenha.Value
Plan9.Cells(lin, 3) = Date
Plan1.Visible = xlSheetVisible
Sheets("Principal").Activate
ActiveWindow.DisplayWorkbookTabs = False
Hide
End If
End Sub


Note, there is a problem further down in your code with the line

Plan1.Visible = xlSheetVisible

marreco
03-16-2013, 07:02 PM
Hi.
can you tell me why is generating this error?

Doug Robbins
03-16-2013, 08:35 PM
It is trying to make visible a Sheet1 (Plan1) but it appears that the Workbook only contains the following objects:

ThisWorkbook (EstaPasta_de_trabalho)
Plan8 (Users)
Plan9 (Plan4)

The next line of code is supposed to activate a sheet with the name of "Principal" However, there is no sheet with that name in the workbook.

marreco
03-17-2013, 04:36 AM
Hi.
In my original file I have all tabs, so that I had removed the file to become lighter after depositing it in the forum.

Anyway is showing a message "False"

snb
03-17-2013, 04:38 AM
Why asking a username and password if you can use


application.username

environ("username")
environ("computername")

With CreateObject("wscript.network")
c01 = .COMPUTERNAME
c02 = .UserName
c03 = .USERDOMAIN
End With

marreco
03-17-2013, 05:04 AM
Hi.
with this command, I can use different users on the same PC?

marreco
03-17-2013, 04:10 PM
Hi.
someone can tell me, why is giving this message to the log?
* "False"