Changing public variable via form (1 Viewer)

Abbos

Registered User.
Local time
Today, 03:17
Joined
May 11, 2005
Messages
64
Hi,

I have 6 public variables as strings and just below where they are defined I have the following code:

Code:
Sub SetVariables()
pass1 = "one"
pass2 = "two"
pass3 = "three"
pass4 = "four"
pass5 = "five"
pass6 = "six"
End Sub

All works fine however I am trying to create a small Admin form which allows a user to change the password. On the I have check boxes which relate to the different password. When check box 1 is ticked for example it enables a text box. The user then can type in the new password and click ok.

The problem is that it is not setting the new password value.

Here is the code I have:

Code:
pass1 = Text21.Value

Can anyone help?
 

FireStrike

Registered User.
Local time
Yesterday, 22:17
Joined
Jul 14, 2006
Messages
69
text boxes don't use the .value, they use .text. If you want to set your variable to the text in a text box you will want to use.

pass1=text21.text

if you use this you will need to give text21 the focus, you can also use the following to get around that.

pass1=text21

either should work.
 

Abbos

Registered User.
Local time
Today, 03:17
Joined
May 11, 2005
Messages
64
Thanks. I have tried that but it doesn't work. I have even tried manually assigning a value to the pass1 variable via the form but it won't assign it.

I think it has something to do with me assigns the values of the variables in the module just under where I have declared them as public.

Could this be the issue?
 

boblarson

Smeghead
Local time
Yesterday, 19:17
Joined
Jan 12, 2001
Messages
32,059
So, just to verify - you are Dimming the variables in a MODULE and not a Form's Module?

And, you are using:

Code:
' under Declarations
Public pass1 As String, pass2 As String, pass3 As String
Public pass4 As String, pass5 As String, pass6 As String

Public Sub SetVariables()
pass1 = "one"
pass2 = "two"
pass3 = "three"
pass4 = "four"
pass5 = "five"
pass6 = "six"
End Sub

Make sure you publicly declare the sub too, or it won't be available to you outside of your Module.
 
Last edited:

Abbos

Registered User.
Local time
Today, 03:17
Joined
May 11, 2005
Messages
64
Hi Bob,

Thanks for the reply. I tried what you suggested but I'm still having problems. Here is a full copy of my code being used:

MODULE

Code:
Public MyFilter As String
Public mynotes As Boolean
Public mygalleryname As Boolean
Public mycurrentvalue As Boolean
Public mypurchase As Boolean
Public myimage As Boolean

Public pass1 As String
Public pass2 As String
Public pass3 As String
Public pass4 As String
Public pass5 As String
Public pass6 As String

Public Sub SetVariables()
pass1 = "one"
pass2 = "two"
pass3 = "three"
pass4 = "four"
pass5 = "five"
pass6 = "six"
End Sub

The code being used in the form:

Code:
Private Sub Command6_Click()
Dim bSelected As Boolean
Dim strDocName As String
bSelected = False
Call SetVariables

    

    If Check4 = True Then
        pass1 = Text21
        bSelected = True
        MsgBox "Your changes have been applied"
        'DoCmd.Close
    End If
    
    If Check7 = True Then
        pass2 = Text23
        bSelected = True
        MsgBox "Your changes have been applied"
        'DoCmd.Close
    End If
    
    If Check9 = True Then
        pass3 = Text25
        bSelected = True
        MsgBox "Your changes have been applied"
        'DoCmd.Close
    End If
   
    If Check11 = True Then
        pass4 = Text27
        bSelected = True
        MsgBox "Your changes have been applied"
        'DoCmd.Close
    End If
    
    If Check20 = True Then
        pass5 = Text29
        bSelected = True
        MsgBox "Your changes have been applied"
        'DoCmd.Close
    End If
    
    If Check19 = True Then
        pass6 = Text31
        bSelected = True
        MsgBox "Your changes have been applied"
        'DoCmd.Close
    End If
    
    If Not bSelected Then
        MsgBox "No items selected"
    Else
        DoCmd.Close
    End If
End Sub

Can anyone stop the problem?
 

ions

Access User
Local time
Yesterday, 19:17
Joined
May 23, 2004
Messages
785
I am not sure what you are trying to do... but I believe you want to store the passwords in a table. Seems like you want the password to last even after you close the program ... -> put it in a table.
 

Abbos

Registered User.
Local time
Today, 03:17
Joined
May 11, 2005
Messages
64
Gave up with this so went with the work around as you said Ions.

Thanks,
 

Users who are viewing this thread

Top Bottom