Consulting

Results 1 to 2 of 2

Thread: Making a fitness class booking after logging in as a user

  1. #1

    Making a fitness class booking after logging in as a user

    On my booking page, I have a member ID field, Class type field as a dropdown (swimming, circuit etc) and a date field.


    The issue I am having is that when I log in as a user, how do I automatically populate the memberID field on the booking page updated to that user's member ID (logged in user). So that the booking comes under their details. Can you guys share any coding to connect my login to automatically populate the member ID field. Or if there is an alternative way without using member ID to make booking whilst logged in, that would be great too.


    This is my module
    Option Compare Database
    
    
    Public CurrentUserID As String
    
    
    Public Function setUser(user123)
        CurrentUserID = user123
    End Function
    
    
    Public Function deleteUser()
        CurrentUserID = ""
    End Function

    My login Code
    Option Compare Database
    Option Explicit
    Private Sub btnLogin_Click()
    
    
    MemberID = Nz(DLookup("[MemberID]", "tblMember", "[Username] ='" & Me.txtUsername.Value & "' And password ='" & Me.txtPassword.Value & "'"), 0)
    If MemberID = 0 Then
        MsgBox "Incorrect Username or Password"
      Else
        MsgBox "You have successfully logged in"
        Call setUser(Me.txtUsername.Value)
        DoCmd.OpenForm "frmHomepage"
        End If
    End Sub

    My homepage
    Option Compare Database
    Public Sub btnBookings_Click()
    
    
        DoCmd.OpenForm "frmBookings", , , "Username = '" & CurrentUserID & "'"
    
    
    End Sub
    
    
    Private Sub btnLogout_Click()
    
    
    Response = MsgBox("Are you sure you want to logout?", vbYesNo + vbQuestion, "Warning")
       If Response = vbYes Then
    
    
            Call deleteUser
            DoCmd.Close
            DoCmd.OpenForm "frmStart"
        Exit Sub
       End If
    
    
    End Sub
    
    
    Public Sub btnMembershipdetails_Click()
    
    
        MsgBox (CurrentUserID)
        'Copy Below to whereever you want member specific details
        DoCmd.OpenForm "frmMemberDetails", , , "Username = '" & CurrentUserID & "'"
    
    
    End Sub

    When I login as a user, I can load up their specific details through the module. I'm assuming it will require me doing something similar to get each user to make a booking when they login.



  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    There are a couple of ways to do this.
    In a Module set up a Global or Public Variable to hold the Login ID.
    A public Variable can be shared by all queries and Forms, so on login you set the publiv variable to the membershipID.
    You can then use simple vba to assign the booking membership id to the public variable in the Form's On Current or On Open Event Procedures.
    Another method would be to add your booking form as a subform to a "Members" Form which uses a query with the currentuserid as a parameter to filter the form to the logged in user. The Membership ID would then be controlled by the Master/Child links of the Forms.
    It depends on how your Relationships are set up.
    You can also use Dlookup.

Posting Permissions

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