Ok. I have 2 userforms and 1 module.
userform with inputboxes for username/password + command button:
Private Sub CommandButton1_Click()
Dim Username As String
Username = TextBox9.Text
Dim password As String
password = TextBox10.Text
If IsNull(Me.TextBox9.Text) Or Me.TextBox9.Text = "" Then
MsgBox "You must enter your username.", vbOKOnly, "Required Data"
Me.TextBox9.SetFocus
Exit Sub
End If
If IsNull(Me.TextBox10.Text) Or Me.TextBox10.Text = "" Then
MsgBox "You must enter your Password (case sensitive).", vbOKOnly, "Required Data"
Me.TextBox10.SetFocus
Exit Sub
End If
Dim temp As String
On Error Resume Next
temp = WorksheetFunction.VLookup(Me.TextBox9.Value, Range("UserRegister"), 1, 0)
If Username = temp Then
Err.Clear
temp = ""
temp = WorksheetFunction.VLookup(Me.TextBox9.Value, Range("UserRegister"), 2, 0)
On Error GoTo 0
If password = temp Then
Sheets("ADMIN").Visible = xlSheetVisible
MsgBox "Password & Username Accepted"
Unload Me
Sheets("ADMIN").Select
Range("A1").Select
Else
Sheets("ADMIN").Visible = xlVeryHidden
MsgBox "Username & Password Combination Not Accepted, Workbook will close"
Unload Me
End If
End If
Call Module1.QueryData1("SELECT UserName,Password FROM data", OutputRange)
End Sub
userform with input box that i named outputrange
Private Sub TextBox1_Change()
TextBox1.Text = "OutputRange"
End Sub
And module
Function QueryData1(Src, OutputRange)
Dim cntStudConnection As ADODB.Connection
Set cntStudConnection = New ADODB.Connection
cntStudConnection.Provider = "Microsoft.Ace.OLEDB.12.0"
cntStudConnection.Open "C:\Users\Hala\Documents\BBB\Dummydata1.accdb"
Set rstNewQuery = New ADODB.Recordset
rstNewQuery.Open Source:=Src, ActiveConnection:=cntStudConnection
Range(OutputRange).CopyFromRecordset rstNewQuery
Set rstNewQuery = Nothing
cntStudConnection.Close
Set cntStudConnection = Nothing
End Function
My database table is called "data" and the columns are username and password
Bookmarks