OK
so i just did a mock up...... i havent tested this but just go through and do the corrections
ill test it now and adjust some parts (most likely) 
Function QueryData1(Src, OutputRange)
Dim Sht as Excel.WorkSheet
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
Set Sht = thisworkbook.Sheets.Add
Sht.Name = "TempSheet101"'<<--LET NAME THE SHEET HERE SO WE CAN DELETE IT EASY LATER
Sht.Range(OutputRange).CopyFromRecordset rstNewQuery
Set rstNewQuery = Nothing
cntStudConnection.Close
Set cntStudConnection = Nothing
End Function
Lets put your old code back and see whats what...
Private Sub CommandButton1_Click()
Dim Sht as Excel.Worksheet <<-- ADD THIS
Dim Username As String
Username = TextBox9.Text
Dim password As String
password = TextBox10.Text
Call Module1.QueryData1("SELECT [UserName], [Password] FROM [data]", OutputRange) '<<---PLACE THIS PART HERE
Set Sht = Thisworkbook.Sheets("TempSheet101") <-- ADD THIS, THIS IS THE NEW SHEET WITH THE DATA RIGHT!
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, Sht.usedRange, 1, 0)' <<-- ADD THE SHEET HERE TOO
If Username = temp Then
Err.Clear
temp = ""
temp = WorksheetFunction.VLookup(Me.TextBox9.Value, Sht.UsedRange, 2, 0) '<<--AND HERE
On Error GoTo 0
If password = temp Then
'Sheets("ADMIN").Visible = xlSheetVisible '<<-- I COMENTED A COUPLE OF LINES HERE
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
End Sub
just work with this for now........ these lookups i dont think will work correctly just yet.... im not used to using excels lookups just give me a minute to test this out......
Bookmarks