Public Const (1 Viewer)

gstylianou

Registered User.
Local time
Today, 08:39
Joined
Dec 16, 2013
Messages
357
Hi, Just a quick question, in order to hold the

How can i write the Public Const Function in order to keep each time the new [LogCustID] from the MainForm? Already i tried the following without results

Option Compare Database
Option Explicit

Public Const cLoggedCustID As String = "Forms!MainForm.LogCustID"

Public Function db() As DAO.Database
'Self-healing database object

Static dbs As DAO.Database

If dbs Is Nothing Then
Set dbs = CurrentDb()
End If

Set db = dbs

End Function
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:39
Joined
May 7, 2009
Messages
19,245
just add it to a Tempvars Collection.

add code to the AfterUpdate event of your LogCustID:

private sub LogCustID_AfterUpdate()
[Tempvars]![custID] = Me!LogCustID
end sub
 

gstylianou

Registered User.
Local time
Today, 08:39
Joined
Dec 16, 2013
Messages
357
just add it to a Tempvars Collection.

add code to the AfterUpdate event of your LogCustID:

private sub LogCustID_AfterUpdate()
[Tempvars]![custID] = Me!LogCustID
end sub
First of all thank you very much, but, is that possible to be done using my code?
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:39
Joined
Sep 21, 2011
Messages
14,310
You are setting it to a string?, not the contents of that control. :(
Plus the form has to be open?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:39
Joined
Oct 29, 2018
Messages
21,474
First of all thank you very much, but, is that possible to be done using my code?
Hi. What exactly did you want the constant to contain? The login information or the name of the form control?
 

Solo712

Registered User.
Local time
Today, 01:39
Joined
Oct 19, 2012
Messages
828
Simply put, constants cannot be used that way. They are numeric or string literals. Use TempVars as arnel suggested or a parameter table to carry the LogCustID content.

Best,
Jiri
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:39
Joined
Sep 21, 2011
Messages
14,310
The MainForm is always opened
But is that before the module is loaded/used?
I just tried that syntax and it told me that it has to be a constant value, which makes sense as it is meant to be a constant, not a value that can change?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:39
Joined
Oct 29, 2018
Messages
21,474
I want to keep the Customer ID each time i change it
Sorry, that doesn't make sense to me. If you change it, then it's different. If you keep it, then it's not changed. Not sure what you're trying to do.
 

gstylianou

Registered User.
Local time
Today, 08:39
Joined
Dec 16, 2013
Messages
357
Basically I try to keep the customer number in memory so that I don't have to mention it in every form like Forms!MainForm.Log|CustID
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:39
Joined
Sep 21, 2011
Messages
14,310
Basically I try to keep the customer number in memory so that I don't have to mention it in every form like Forms!MainForm.Log|CustID
As did I
Code:
    TempVars("EmployeeID").Value = Me.cboEmployeeID.Column(0)
    TempVars("Employee").Value = Me.cboEmployeeID.Column(1)
    TempVars("UserLevel").Value = DLookup("DataOrder", "tblLookup", "LookupID = " & Me.cboEmployeeID.Column(3))
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:39
Joined
Oct 29, 2018
Messages
21,474
Basically I try to keep the customer number in memory so that I don't have to mention it in every form like Forms!MainForm.Log|CustID
Can you show us how you intend to use the constant in your code?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:39
Joined
Feb 19, 2002
Messages
43,293
You don't need to create a constant. You can just define a Public variable in a standard module. OR, use a TempVar

In the Click event of the Login after it is verified:
PublicCustID = Me.CustID
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:39
Joined
Feb 28, 2001
Messages
27,191
Specifically, if you declare something as a constant, you have told Access to protect it forever as it appears in its declaration. You cannot then change it. It is kept in an area where the hardware protects it from change.

Pat's comment is correct. A public variable is perfectly fine for what you want. If you are afraid that having it in a variable means it is temporary... it IS. You just said you wanted to change it. Well, in a variable, you CAN.

It sounds like you fear an unexpected change. THAT would occur because of poor programming techniques, not because of an Access accident. Access will not spontaneously change something. That change will be either intentional or due to human error.
 

gstylianou

Registered User.
Local time
Today, 08:39
Joined
Dec 16, 2013
Messages
357
Specifically, if you declare something as a constant, you have told Access to protect it forever as it appears in its declaration. You cannot then change it. It is kept in an area where the hardware protects it from change.

Pat's comment is correct. A public variable is perfectly fine for what you want. If you are afraid that having it in a variable means it is temporary... it IS. You just said you wanted to change it. Well, in a variable, you CAN.

It sounds like you fear an unexpected change. THAT would occur because of poor programming techniques, not because of an Access accident. Access will not spontaneously change something. That change will be either intentional or due to human error.
Thank you very much
 

gstylianou

Registered User.
Local time
Today, 08:39
Joined
Dec 16, 2013
Messages
357
You don't need to create a constant. You can just define a Public variable in a standard module. OR, use a TempVar

In the Click event of the Login after it is verified:
PublicCustID = Me.CustID
Because of poor knowledge of vba programming, could you please give me a quick module solution example on how can i write it correct?
 

Users who are viewing this thread

Top Bottom