modify modules

G

Guest

I would like my VBA code to modify VBA code?
Can this be done?

I have this Public constant string:
Public Const cODBCConnectStr =
"ODBC;DSN=CA-SQL01-DEV;Description=CA-SQL01-DEV;UID=;DATABASE=FRED;Trusted_Connection=Yes"

I would like code to change the string for example to:
Public Const cODBCConnectStr =
"ODBC;DSN=CA-SQL01-DEV;Description=CA-SQL01-DEV;UID=;DATABASE=MARY;Trusted_Connection=Yes"

All I did was change the database from FRED to MARY.

I already have different constants that I just comment on or off as many
developers do. I also use a table to store the constant string but I would
like code to change code.

thanks for any help...
 
M

Marshall Barton

Bret said:
I would like my VBA code to modify VBA code?
Can this be done?

I have this Public constant string:
Public Const cODBCConnectStr =
"ODBC;DSN=CA-SQL01-DEV;Description=CA-SQL01-DEV;UID=;DATABASE=FRED;Trusted_Connection=Yes"

I would like code to change the string for example to:
Public Const cODBCConnectStr =
"ODBC;DSN=CA-SQL01-DEV;Description=CA-SQL01-DEV;UID=;DATABASE=MARY;Trusted_Connection=Yes"

All I did was change the database from FRED to MARY.

I already have different constants that I just comment on or off as many
developers do. I also use a table to store the constant string but I would
like code to change code.

You do NOT want to be modifying VBA code on the fly. That
would be a heavy duty operation that would greatly increase
your program's vulnerability to corruption.

Since a Constant is constant, it's a bit of an oxymoron to
talk about changing it. I suggest that you find another way
to accomplish this activity.

How about this?
Public Const cODBCConnectStrA =
"ODBC;DSN=CA-SQL01-DEV;Description=CA-SQL01-DEV;UID=;DATABASE="
Public Const cODBCConnectStrB = ";Trusted_Connection=Yes"
Dim sConnect As String
sConnect = cODBCConnectStrA & strDBName & cODBCConnectStrB
 

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