New to these forums so I hope I am posting this to the right area?
I am in the process of learning Access again after an absence of around 9 years off and on.
My new project is to adapt a DB I designed in Alpha Five to work in Access I have version 2013 but at work we are still using 2000!
I would like to declare Global or Public variables from a table so they can be added to or edited easily. I had the following function to do this with Alpha Five but at the moment my lack of knowledge of Access VBA is making this task difficult can anyone point me in the right direction or advise a better approach?
Here is the function that I use in Alpha:
FUNCTION udVars AS A (udTabName AS C )
dim codeStr as c
t=table.open_session(udTabName,file_ro_shared)
t.fetch_first()
while .not. t.fetch_eof()
'add all lines to a single crlf() delimited string
codeStr = codeStr + "dim global "+trim(t.My_var)+" as "+alltrim(t.My_type)+crlf()
codeStr = codeStr + alltrim(t.My_var) + " = convert_type(\""+alltrim(t.My_value)+"\",\""+alltrim(t.My_type)+"\")"+crlf()
t.fetch_next()
end while
t.close()
if codeStr <> ""
codestr = strtran(codeStr,chr(34)+chr(34),chr(34)) ' replace double quotes chr(34)+chr(34) with a single quote chr(34)
evaluate_template(codeStr)
end if
END FUNCTION
It opens a table reads in the records and then makes them into a string the string would look something like this:
"Public EuroRate as Single = 0.885"
I would then need to use this string to declare the variables but not sure what command to use - I was looking at the Eval function last night but couldn't get this to work...
The table would hold strings for all the above so you would have:
My_Var (variable name)
My_Typ (type of variable e.g. Single)
My_Val (value e.g. 0.885)
The table would hold as many variables as required, some would be dates, some paths for making directories and some would be numbers.
Anyone got any idea if this would work in Access or would an alternative way of doing this be better?
I am in the process of learning Access again after an absence of around 9 years off and on.
My new project is to adapt a DB I designed in Alpha Five to work in Access I have version 2013 but at work we are still using 2000!
I would like to declare Global or Public variables from a table so they can be added to or edited easily. I had the following function to do this with Alpha Five but at the moment my lack of knowledge of Access VBA is making this task difficult can anyone point me in the right direction or advise a better approach?
Here is the function that I use in Alpha:
FUNCTION udVars AS A (udTabName AS C )
dim codeStr as c
t=table.open_session(udTabName,file_ro_shared)
t.fetch_first()
while .not. t.fetch_eof()
'add all lines to a single crlf() delimited string
codeStr = codeStr + "dim global "+trim(t.My_var)+" as "+alltrim(t.My_type)+crlf()
codeStr = codeStr + alltrim(t.My_var) + " = convert_type(\""+alltrim(t.My_value)+"\",\""+alltrim(t.My_type)+"\")"+crlf()
t.fetch_next()
end while
t.close()
if codeStr <> ""
codestr = strtran(codeStr,chr(34)+chr(34),chr(34)) ' replace double quotes chr(34)+chr(34) with a single quote chr(34)
evaluate_template(codeStr)
end if
END FUNCTION
It opens a table reads in the records and then makes them into a string the string would look something like this:
"Public EuroRate as Single = 0.885"
I would then need to use this string to declare the variables but not sure what command to use - I was looking at the Eval function last night but couldn't get this to work...
The table would hold strings for all the above so you would have:
My_Var (variable name)
My_Typ (type of variable e.g. Single)
My_Val (value e.g. 0.885)
The table would hold as many variables as required, some would be dates, some paths for making directories and some would be numbers.
Anyone got any idea if this would work in Access or would an alternative way of doing this be better?
Last edited: