I Create a userform log in form. How do I get that loggers user name. not the application name or the environ(username).

cmxulb

Board Regular
Joined
Nov 24, 2020
Messages
52
Office Version
  1. 365
Platform
  1. Windows
I Create a userform log in form. How do I get that loggers user name. not the application name or the environ(username). This form below user name .

1606235325237.png
1606235442975.png
I need to add that user name here


Please Help! Thank You!
 
Where is the code that you showed? Is it in the login userform module?
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Userform1
1606237745954.png


module
. cells(irows), 10=
 
Last edited:
Upvote 0
Can you please just answer my question, with words not jumbled images?
 
Upvote 0
Can you please just answer my question, with words not jumbled images?
Userform1 - Login form

Private Sub CommandButton1_Click()


Dim user As String

Dim password As String

user = Me.txtUserID.Value

password = Me.txtPassword.Value

If (user = "admin" And password = "admin") Or (user = "user" And password = "user") Or (user = "Dario" And password = "Dario") Then

Unload Me
Application.Visible = True

Else

If LoginInstance < 3 Then

MsgBox "Invalid login credentials. Please try again.", vbOKOnly + vbCritical, "Invalid Login Details"
LoginInstance = LoginInstance + 1

Else

MsgBox "You have exceeded the maximum number of login attempts.", vbOKOnly + vbCritical, "Invalid Credentials"
Unload Me
ThisWorkbook.Close Savechanges:=False
Application.Visible = True
LoginInstance = 0

End If

End If
End Sub


Module -Appl.-Form

Sub Submit()

Dim sh As Worksheet
Dim iRow As Long

Set sh = ThisWorkbook.Sheets("Database")

If frmForm.txtRowNumber.Value = "" Then

iRow = [Counta(Database!A:A)] + 1
Else

iRow = frmForm.txtRowNumber.Value

End If


With sh

.Cells(iRow, 1) = "=Row()-1" 'Dynamic Serial Number

.Cells(iRow, 2) = frmForm.txtMaterialID.Value

.Cells(iRow, 3) = IIf(frmForm.optLarge.Value = True, "Large", "Small")

.Cells(iRow, 4) = frmForm.cmbValve.Value

.Cells(iRow, 5) = IIf(frmForm.CheckYes.Value = True, "Yes", "No")

.Cells(iRow, 6) = frmForm.txtintfineflow.Value

.Cells(iRow, 7) = frmForm.txtintcoarseflow.Value

.Cells(iRow, 8) = frmForm.txtFineFlow.Value

.Cells(iRow, 9) = frmForm.txtCoarseFLow.Value

.Cells(iRow, 10) = UserForm1.txtUserID.Value

.Cells(iRow, 11) = [Text(Now(), "MM-DD-YYYY HH:MM:SS")]

.Cells(iRow, 12) = frmForm.txtComments.Value


End With


End Sub
 
Upvote 0
Reason Application.Username and Environ("username") wont work it because I have 5 user using the same the PC login user name and password.
 
Upvote 0
Your code cannot get the value from the text box, because you have closed the userform & therefore there is nothing to get.
Remove this from the command button click
VBA Code:
Dim user As String
and put it at the top of a standard module (before any code) and then use
VBA Code:
.Cells(iRow, 10) = user
 
Upvote 0
Your code cannot get the value from the text box, because you have closed the userform & therefore there is nothing to get.
Remove this from the command button click
VBA Code:
Dim user As String
and put it at the top of a standard module (before any code) and then use
VBA Code:
.Cells(iRow, 10) = user
if i take Dim user As string
I get this error

1606248351058.png
 
Upvote 0
Did you put it at the top of a regular module (before any code)?
 
Upvote 0
You have not followed my instructions.
That said it needs to be
VBA Code:
Public user As String
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,545
Members
449,317
Latest member
chingiloum

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top