Hi im very new to all this programing lark but was wondering if some one could tell me what im doing wrong, I am tring to creat a login box so you have to enter the corect details to use my form but it keeps filling in the textboxes with the correct info when you hit ok. I hope some one can point out what im doing wrong its probably something really stupid ;). Hers is my code

Private Sub cmdLogin_Click()


Dim password As String
Dim username As String

username = "admin"
password = "secret"


Me.Txtuser.Text = username
Me.Txtpass.Text = password


If username = "admin" And password = "secret" Then


MsgBox("Access Granted", vbOK, "Welcome to West One Admin ")

WestOneAdmin.Show()


Else

MsgBox("Please Try Again")

End If


End Sub

Many Thanks in advanced

Member Avatar for Dukane

You have

Me.Txtuser.Text = username
Me.Txtpass.Text = password

backwards.

take out:

Me.Txtuser.Text = username
Me.Txtpass.Text = password

take out:

Me.Txtuser.Text = username
Me.Txtpass.Text = password

Don't take it out, then you can't check if it's right. Dukane was partially correct, you have it backwards. You actually need to make 2 more strings to store the input values from the textboxes. When you assign values to strings, you need to put the string first, then the value.

So, try this:

Dim password As String
Dim username As String


Dim passcheck As String
Dim usercheck As String


username = "admin"
password = "secret"

' These 2 strings are to store input from textboxes
passcheck = Txtuser.Text 
usercheck = Txtpass.Text
' You can switch admin and secret here with username and password
If usercheck = "admin" And passcheck = "secret" Then

Hi im very new to all this programing lark but was wondering if some one could tell me what im doing wrong, I am tring to creat a login box so you have to enter the corect details to use my form but it keeps filling in the textboxes with the correct info when you hit ok. I hope some one can point out what im doing wrong its probably something really stupid ;). Hers is my code

Private Sub cmdLogin_Click()


Dim password As String
Dim username As String

username = "admin"
password = "secret"


Me.Txtuser.Text = username
Me.Txtpass.Text = password


If username = "admin" And password = "secret" Then


MsgBox("Access Granted", vbOK, "Welcome to West One Admin ")

WestOneAdmin.Show()


Else

MsgBox("Please Try Again")

End If


End Sub

Many Thanks in advanced

Here's some codes to solve your problem:

Private Sub cmdLogin_Click()


        Dim password As String
        Dim username As String

        username = "admin"
        password = "secret"

       'Let the user fill this out, so do not assign any value to it like you did in your code
        Me.Txtuser.Text = ""
        Me.Txtpass.Text = "" 

       'Let us evaluate the value of the Textboxes and it should MATCH with your strings.

        If Me.Txtuser.Text =username  And Me.Txtpass.Text =  password  Then

            MsgBox("Access Granted", vbOK, "Welcome to West One Admin ")

            WestOneAdmin.Show()


        Else

            MsgBox("Please Try Again")

        End If


    End Sub

If Me.Txtuser.Text has value = "admin" then it is true/correct.
If Me.Txtpass.Text has value = "secret" then it is also true/correct.

I hope this would help.

Thanks all thats has got it sorted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.