Making a fitness class booking after logging in as a user

2k7mmurtaza

New member
Local time
Today, 19:39
Joined
Mar 5, 2018
Messages
5
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
Code:
Option Compare Database

Public CurrentUserID As String

Public Function setUser(user123)
    CurrentUserID = user123
End Function

Public Function deleteUser()
    CurrentUserID = ""
End Function

My login Code
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
Code:
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.
 
Last edited:
OK, a couple of remarks for future reference.

1. Technically and based on what they do, your module's functions are actually subroutines because you don't return a value to the function. You are using them to populate a global, which is OK. However, if this is ALL you were going to do, you don't need this kind of code anyway. If you have a one-line operation (set public variable to some other variable) there is no need to build a subroutine. (If there were more lines having to do with validation or other record-keeping, my comments would be different.)

2. In your btnLogin_Click routine, at the point where you have decided this is a valid user, you have the member ID right there and you already know how to store values in public variables. Store anything you need in public variables declared in your general module. If they are public, you can fetch or store things from anywhere in the app.

3. I'm not sure what you intended with the message box in your btnMembershipdetails_Click code, but let's just say it "looks odd" and probably would do something odd.

Your specific question was to figure out how to remember your member's ID, and I addressed that. Please consider that since we don't know the details of your project, we have no way to understand what you want to do unless you ASSUME we know nothing about the project when you describe things in preparation for questions. This should not be taken as chastisement, merely a suggestion to get you better results in the future.
 

Users who are viewing this thread

Back
Top Bottom