login / username

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #16
    Originally posted by dale5804
    hi...sorry, as you may have guessed, still new at this vb stuff. not quite sure what your telling me to do.
    Hi Dale. Simplest way if you are not sure is to create a new, blank, module (select Modules in the database window, then New). The VB editor will open in a new, blank, module. From the VB editor window go to the form code module in which the ReturnUsername function is currently placed, select the function, then cut that definition from the form's module. Re-select the new, blank, code module and paste the function in there instead. It is so short you could retype it if you have to.

    Save all changed modules. Compile the code to ensure there are no accidental errors.

    This should resolve the problem you are experiencing, which is because one form's code module cannot see the definition of ReturnUsername in the other.

    -Stewart

    Comment

    • dale5804
      New Member
      • Nov 2007
      • 48

      #17
      do i need to call the module anything for it to work?

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #18
        Originally posted by dale5804
        do i need to call the module anything for it to work?
        Any module name will do, Dale. Even t he default of Module1, although I would change it to something such as General Routines.
        -Stewart

        Comment

        • dale5804
          New Member
          • Nov 2007
          • 48

          #19
          Originally posted by Stewart Ross Inverness
          Any module name will do, Dale. Even t he default of Module1, although I would change it to something such as General Routines.
          -Stewart
          thought so, so i did what u said, and still having the same problem. any other ideas. cheers

          Comment

          • Stewart Ross
            Recognized Expert Moderator Specialist
            • Feb 2008
            • 2545

            #20
            Originally posted by dale5804
            thought so, so i did what u said, and still having the same problem. any other ideas. cheers
            No other ideas, sorry. It works in my test system as long as the function is in scope. You must be overlooking something, but I'm afraid at this distance I simply can't think of any relevant explanation. You have declared it as a Public function? Have you tested it in the VB immediate window as I suggested much earlier? You could set break points and step through the code one line at a time, but I think you would not be in a position to benefit from this unless you know what you are looking for. I would recommend you read a good introductory text on VBA programming.

            I use system functions to retrieve the username of the currently-logged-in user from the windows API in my own systems without any hitches at all. Although I am not querying a value supplied by the user, the return values are done in a similar way to what you have been advised.

            Sorry it has not worked out for you after all the effort you have put in.

            -Stewart

            Comment

            • dale5804
              New Member
              • Nov 2007
              • 48

              #21
              hi Stewart, thanks for all you help. i will keep trying, but you've been a star. wouldn't have got this far without your advice. cheers

              Comment

              • Stewart Ross
                Recognized Expert Moderator Specialist
                • Feb 2008
                • 2545

                #22
                One final thing: move the global variable Username to your new code module as well. Same issue - the variable needs to be in scope.

                -Stewart

                Comment

                • Stewart Ross
                  Recognized Expert Moderator Specialist
                  • Feb 2008
                  • 2545

                  #23
                  Hi again Dale. One other overlook on my part is that the ReturnUsername function should have been typed as a String. This is what happens when I take a working function of my own and change it to post it.

                  The global and the function, both now in your public module, should be:
                  [CODE=vb]Public UserName as String

                  Public Function ReturnUserName () as String
                  ReturnUserName = UserName
                  End Function
                  [/CODE]

                  and final thing to try, because there are no parameters for ReturnUserName remove the brackets in timestamp function call:
                  [code=vb]...vbNewLine & ReturnUserName & ...[/code]
                  So near yet so far...

                  -Stewart

                  Comment

                  • dale5804
                    New Member
                    • Nov 2007
                    • 48

                    #24
                    Originally posted by Stewart Ross Inverness
                    Hi again Dale. One other overlook on my part is that the ReturnUsername function should have been typed as a String. This is what happens when I take a working function of my own and change it to post it.

                    The global and the function, both now in your public module, should be:
                    [CODE=vb]Public UserName as String

                    Public Function ReturnUserName () as String
                    ReturnUserName = UserName
                    End Function
                    [/CODE]

                    and final thing to try, because there are no parameters for ReturnUserName remove the brackets in timestamp function call:
                    [code=vb]...vbNewLine & ReturnUserName & ...[/code]
                    So near yet so far...

                    -Stewart
                    cheers, getting there, the code doesnt throw an error up, but when the data is transferred, it prints the user as '1' then the time/date stamp?? I've also tried and removed the brackets as you suggested, and i stll get 1 as the username???

                    Comment

                    • Stewart Ross
                      Recognized Expert Moderator Specialist
                      • Feb 2008
                      • 2545

                      #25
                      [font=Arial]
                      Originally posted by dale5804
                      cheers, getting there, the code doesnt throw an error up, but when the data is transferred, it prints the user as '1' then the time/date stamp?? I've also tried and removed the brackets as you suggested, and i stll get 1 as the username???
                      Hi Dale. I did not check what was in the combo box in the DatabaseDev code; it is clearly the employee number which is in the default column. This one is easily fixed.[/font]

                      [font=Arial]In the cboEmployee after update, change the code as follows:
                      [code=vb]Private Sub cboEmployee_Aft erUpdate()
                      UserName = cboEmployee.col umn(1) '<<< This line sets the global variable to
                      ' the value in the entry combo
                      'After selecting user name set focus to password field
                      Me.txtPassword. SetFocus
                      End Sub[/code]
                      This will refer to the name in the second column of the combo box (referred to as column(1) because the numbering is from 0).
                      -Stewart
                      [/font]

                      Comment

                      • dale5804
                        New Member
                        • Nov 2007
                        • 48

                        #26
                        Originally posted by Stewart Ross Inverness
                        [font=Arial]Hi Dale. I did not check what was in the combo box in the DatabaseDev code; it is clearly the employee number which is in the default column. This one is easily fixed.[/font]

                        [font=Arial]In the cboEmployee after update, change the code as follows:
                        [code=vb]Private Sub cboEmployee_Aft erUpdate()
                        UserName = cboEmployee.col umn(1) '<<< This line sets the global variable to
                        ' the value in the entry combo
                        'After selecting user name set focus to password field
                        Me.txtPassword. SetFocus
                        End Sub[/code]
                        This will refer to the name in the second column of the combo box (referred to as column(1) because the numbering is from 0).
                        -Stewart
                        [/font]
                        thankyou so much Stewart. it works :-)
                        Last edited by dale5804; Mar 4 '08, 08:39 PM. Reason: typo

                        Comment

                        Working...