Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a public variable in a private module

Tags:

vba

ms-access

Basically It's a login form and i'm trying to save the ID which is the Me.CBOUsername.Column(0) but I get an error when i try to call it in another form.

Option Compare Database
Option Explicit
Public ID_ As String
Private Sub Command4_Click()
    Dim strCBOPass As String
    Dim strPassword As String

    strCBOPass = Me.CBOUsername.Column(1)
    strPassword = Me.txtpassword

    If strCBOPass = strPassword Then
        MsgBox "Login Successful!"
        DoCmd.OpenForm "Form1"
        DoCmd.Close acForm, Me.Name
        ID_ = Me.CBOUsername.Column(0)

    Else
        MsgBox "login Unsuccessful!"
    End If
End Sub
like image 290
Billy Avatar asked Feb 24 '26 12:02

Billy


1 Answers

It may be a little easier to explain this way.

As an example of a global variable:

Public Global_Variable1 as String

Public Sub Procedure1()
    Global_Variable1 = "Test"
End Sub

Public Sub Procedure2()
    Call Procedure1
    MsgBox (Global_Variable1)  'return Test
End Sub

enter image description here

Add the module by right-clicking, and using Insert > Module

like image 84
Jiggles32 Avatar answered Feb 27 '26 03:02

Jiggles32



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!