Results 1 to 8 of 8
  1. #1
    rameshjctr is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2016
    Posts
    16

    nothing happens

    friends,
    i have a table USERS with PEN number,PASSWORD string as fields. in my login screen when i till up and click login cmd-button nothing happens.
    when i hit login it shold open DETAILS form.
    the code for Login cmd button is given below:

    Private Sub Command7_Click()
    Dim uname As Long
    Dim passwd As String
    Form.Refresh
    If Me!Text1 = "" And Me!Text2 = "" Then
    Me.SetFocus
    Me!Text1.SetFocus


    Else
    uname = Me!Text1
    passwd = Me!Text2
    If (uname = DLookup("[PEN]", "USERS", "[PEN]= " & Me!Text1.Value) And passwd = DLookup("[PASSWORD]", "USERS", "[PASSWORD]= '" & Me!Text2.Value & "'")) Then
    DoCmd.OpenForm ("DETAILS")
    Else
    End If
    End If
    End Sub

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    better to give your controls meaningful names - is it called Command7? so is the code running?

    and this code can be better written as

    If DCount("*", "USERS", "[PEN]= " & Text1 & " AND [PASSWORD]= '" & Text2 & "'")=1 then

    Also if PEN is not numeric, you need to include single quotes as you have for password

  3. #3
    rameshjctr is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2016
    Posts
    16
    sure ajax. this is a crude one. i am making an original one with meaningful names. thanks for your suggestions.

  4. #4
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    a couple of suggestions:
    If Me!Text1 = "" And Me!Text2 = ""
    ..... doesn't look correct to my eye and guessing it should be: If Me.Text1 = Me.Text2

    it often is better to do the DCount of a query - and put the criteria in the query: rather than put the criteria in the DCount clause. This is because it is much easier to test. One can manually fire the query to see if it is working as one intends.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I'm guessing that

    If Me!Text1 = "" And Me!Text2 = "" Then

    is meant to check for the lack of data in those Controls...but it's actually only checking for Zero-Length Strings! 'Empty' Controls, in Access, are usually Null. To check for both ZLSs and Nulls, you can use a number of hacks, including

    If Nz(Me!Text1, "") = "" And Nz(Me!Text2, "") = "" Then

    And as Ajax said, the exact syntax depends on the Datatypes of Fields in the Where Clause.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    rameshjctr is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2016
    Posts
    16
    thanks for your valuable suggestions friends. i am new to this access programming. with little knowledge of programming i am trying to do a project of my own. actually i started it 1 month back. everytime i struck upon something and find it very difficult to find a way out. now i have u friends to help me. this project is done only on my interest in programming where i am still a student. hoping to get valuable advice from you experts. thanking you once again.

    ramesh

  7. #7
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Good luck to you rameshjctr. You've come to the right place with your questions. I've found people here to be quite helpful no matter what your skill level.

  8. #8
    rameshjctr is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2016
    Posts
    16
    dear friends,
    now the things are working fine for time being. hope it will continue. thanks a lot for your valuable helps. thanks everybody.

    ramesh

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums