add field to a back end on pc running access RUNTIME

M

massimo

Hi,
I've split my db, called crm.db in 2 parts. The second (crm_db.mdb)
contains data and the first, only linked tables and forms.
The pcs where I distribute this application are running "runtime"
version of access 2000.
I've tried to alter an existing field, and also to add a new field, but
I get only a runtime error.
The same functions on a pc running full access 2000 works perfect.
What can I do?

Thanks.

Max
 
R

Rick Brandt

massimo said:
Hi,
I've split my db, called crm.db in 2 parts. The second (crm_db.mdb)
contains data and the first, only linked tables and forms.
The pcs where I distribute this application are running "runtime"
version of access 2000.
I've tried to alter an existing field, and also to add a new field,
but I get only a runtime error.
The same functions on a pc running full access 2000 works perfect.
What can I do?

Must be something else going on. I update table strutures in the Back End of
runtime apps via code in the Front End frequently and have never had any
problems.
 
A

Albert D. Kallal

I get only a runtime error.
The same functions on a pc running full access 2000 works perfect.
What can I do?

You should as a rule "test" you code on your pc, and just use the /runtime
switch to get the "same" effect.

The one thing that "gets" you is that you can't launch, or automate a 2nd
copy of ms-access using the runtime (the reason for this is that ms-access
as runtime REQUIRES A FILE NAME as parameters, and when you automate, this
is NOT possible to provide).

I can't remember why, but a number of years ago, my code to modify the back
end also used automaton..and when I went to runtime mode...it failed.

So, the simple solution is to have your code OPEN the back end database, and
modify it. You should NOT need to automate a 2nd copy of ms-access to create
your modifying.

so, here how I do this:

' check table locations...and add default capacity...
' check for Locations capacity field

Dim nF As DAO.Field
Dim nT As DAO.TableDef
Dim nR As DAO.Relation

Dim rst As DAO.Recordset
Dim dbTable As DAO.TableDef
Dim db As DAO.Database
Dim strTemp As Variant


Set rst = CurrentDb.OpenRecordset("Locations")
On Error GoTo AddLocationsCapacity
strTemp = rst!Capacity.Name

rst.Close
Set rst = Nothing

return

AddLocationsCapacity:

rst.Close

strToDB = strBackEndPath

Set db = OpenDatabase(strToDB)

Set nT = db.TableDefs("Locations")
nT.Fields.Append nT.CreateField("Capacity", dbLong)
nT.Fields.Refresh
db.Close
Set db = Nothing

Set rst = CurrentDb.OpenRecordset("Locations")
resume next


Notice how we simply grab (create) a "db" object on the back end.

So, if we were not split, we would go:

set db = currentdb

now, we use
set db = OpenDataBase("path to back end")

From this point on, you can use your alter table commands etc...

db.Execute "alter table......"

when done,
db.Close

So, don't launch a 2nd copy of ms-access via automaton...it not only
resource intensive, but simply can't be done via the runtime....

The above "error" handling is how I ignore the creating of the field the 2nd
time....
 
M

massimo

Peter Hibbs said:
You could also look at -
http://www.rogersaccesslibrary.com/Otherdownload.asp?SampleName='BE Update Utility.mdb'
which allows you to add fields and tables to the back end
automatically (if that is is what you are looking for).

Peter Hibbs.

thanks. I've made a trivial mistake, I didn't pass the full path of BE.
Now I've another problem... How to change the default value for an
"existing" field in BE?
having a look here,
http://support.microsoft.com/?scid=kb;en-us;180841&x=8&y=16, it seems
that ALTER TABLE under DAO doesn't support this..
"Microsoft Access DDL supports the ALTER TABLE DDL statement. This statement
is useful when you need to remove or add a field to an existing table.
Note: This statement won't let you alter an existing field in an Access
table (for example, to change the field's data type). "

thanks.
 
P

Peter Hibbs

Massimo.

I'm not entirely sure what you are trying to do but the Back End
Update utility that I indicated CAN change the data type of an
existing field in the back end file and also set the Default value of
the field (at the same time, if you wish). Obviously you would have to
be careful when changing a field type because you could lose some data
but it can be done. I don't know if it works where the front end is
using a 'run time' version as I have not tried that configuration. I
suggest you study the code in this utilty to see if it can be used to
do what you want.

Good luck.

Peter Hibbs.
 

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