Changing a code Variable from a form

G

Guest

Changing a code Variable from a form


I want to be able to change a code variable that I have set in a module from
a form. Is this possible? I am building it an adp but it should be the same
as with any other access database. I just don’t know how to change a module
from a form or even if it’s possible.

Below is the code that I have.

Is it possible for me to make a form control that I can use to change
“constant_Unit†in access 2002?

Thanks



-----------------
Option Compare Database

Global Unit As String, UnitName As String
Global ReportCaption As String

Public Sub DeclairConstants()

Dim cnnt1 As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strDBName As String
Dim intCount As Integer
Dim strTable As String
Dim fld As ADODB.Field
Dim constant_Unit As String

constant_Unit = "WAY8AA" '*** THIS IS THE VARIABLE, CONSTANT I WANT
TO CHANGE.


strTable = "tbl_Constants"
Set cnnt1 = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.CursorType = adOpenForwardOnly
rst.LockType = adLockReadOnly
rst.Open "tbl_Constants", cnnt1
rst.MoveFirst
rst.Find ("UIC = '" & constant_Unit & "'") '********* finds the record
that I want to work with ********

UnitName = rst!Name
UIC = rst!UIC

rst.Close
Set rst = Nothing



End Sub
 
V

Van T. Dinh

Instrad of setting it in (the design of) the code, try passing the value as
the argument of the Sub. For example, you can use the dec:

Public Sub DeclairConstants(strUnit As String)

and later:

rst.Find ("UIC = '" & strUnit & "'")

When you call the Sub simply pass the value you want, like:

Call DeclairConstants("WAY8AA")
 
G

Guest

The problem is that i want it to use the setting as a default. I just want
to give them the option to change the default with a form. I have a more
detailed version of t his code running when I start the app. This string
pretty much sets all the filters for the forms and sets the headers and
stuff. Does that make sence?

Basicaly I don't want to have to open the form every time, just when I want
to copy the application for another group and don't want someone to have to
go into the code to edit the constants. I'm trying to make things easier for
the guys when i leave.
 
V

Van T. Dinh

You can use Optional argument and set the DefaultValue for the optional
argument like:

Public Sub DeclairConstants(Optional strUnit As String = ""WAY8AA")

You need to check in Access VB Help on how to know when a value is passed to
the Sub and use the passed value and when to use the DafaultValue.
 
G

Guest

Ok, i think i see what you mean, and when you change the value, have it
change the default in the form also, so it'll actualy save it like that.

My man, you are brilliant!
 
V

Van T. Dinh

Your solution doesn't sound like what I advised.

However, I take the credit <bg> for giving some ideas so that you could work
it out. In fact, this is the best way to use newsgroups: working out your
own solutions with basic ideas from others.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top