Public Const

gstylianou

Registered User.
Local time
Today, 03:58
Joined
Dec 16, 2013
Messages
359
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
 
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
 
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?
 
You are setting it to a string?, not the contents of that control. :(
Plus the form has to be open?
 
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?
 
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
 
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?
 
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.
 
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
 
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))
 
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?
 
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
 
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.
 
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
 
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

Back
Top Bottom