Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2003
    Location
    OK
    Posts
    10

    Question Unanswered: Global Variable question

    Hi,

    I use a Global Variable to store the username from a login form I created. I now would like to populate my tables with that field, but I do not know how to make the variable a default value.

    I also would like to display it on a form, what would be the syntax? Please let me know,

    Thank you for your help,

    Steve

  2. #2
    Join Date
    Oct 2003
    Location
    US
    Posts
    343

    Re: Global Variable question

    Make a function which can return the value of this global variable as the function value. for example.

    public gstrUserID as String

    Public function UserID() as String
    userID=gstrUserID
    End Function

    Then in your table design place this variable in the default value property.

    To display it on the form, bound this function to the text box.

    You are done.



    Originally posted by stfarm
    Hi,

    I use a Global Variable to store the username from a login form I created. I now would like to populate my tables with that field, but I do not know how to make the variable a default value.

    I also would like to display it on a form, what would be the syntax? Please let me know,

    Thank you for your help,

    Steve

  3. #3
    Join Date
    Jul 2003
    Location
    OK
    Posts
    10
    Thank you very much for your help.

    I created the function, and now I would like to display it in a form. What syntax do I use?
    I am new to all this, sorry about my ignorance.

    Steve

    Maybe I should display my code.........Here it is:


    Public UsernameVar As String


    Private Sub Login_Click()

    DoCmd.SetWarnings False
    'Checks the Username and Password then performs commands if both are correct
    'Screen.MousePointer = 11
    On Error GoTo Pass
    'DoCmd.Close acForm, "Splash"
    Dim rs As DAO.Recordset
    Dim qd As DAO.QueryDef
    Set qd = CurrentDb.QueryDefs("LogonCheck")
    qd.Parameters(0) = Me.UserName
    qd.Parameters(1) = Me.UserPass
    Set rs = qd.OpenRecordset
    Dim checksum1

    If IsNull([UserName]) Then
    MsgBox "Incorrect UserName or Password"
    ' Screen.MousePointer = 0
    Exit Sub
    End If

    If IsNull(Me.UserPass) Then
    MsgBox "Incorrect UserName or Password"
    'Screen.MousePointer = 0
    Exit Sub
    End If

    checksum1 = rs!checksum

    If checksum1 = "" Then
    checksum1 = 1
    End If

    If checksum1 = 0 Then 'if Login is correct put command lines next
    UsernameVar = [UserName]
    MsgBox (UsernameVar)
    DoCmd.OpenForm ("PolyCart Entry Form by Address")


    ElseIf checksum1 <> 0 Then
    MsgBox "Incorrect UserName or Password"
    UserPass = ""
    UserPass.SetFocus

    End If

    Pass:
    Resume Next
    End Sub


    Public Function UserID() As String
    UserID = UsernameVar
    End Function
    Last edited by stfarm; 10-23-03 at 12:57.

  4. #4
    Join Date
    Oct 2003
    Location
    US
    Posts
    343
    Have a text box say txtUserID on your form. In its control source property Type

    =UserID()

    Remember UserID() is the function that returns your global variable.


    Originally posted by stfarm
    Thank you very much for your help.

    I created the function, and now I would like to display it in a form. What syntax do I use?
    I am new to all this, sorry about my ignorance.

    Steve

  5. #5
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    I use a label ...

    CurrentUserLbl.Caption=MyUserID

  6. #6
    Join Date
    Oct 2003
    Location
    US
    Posts
    343

    Talking

    Looks like MOwen is from Michigan. !!!

    Originally posted by M Owen
    I use a label ...

    CurrentUserLbl.Caption=MyUserID

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •