Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / December 2003

Tip: Looking for answers? Try searching our database.

DAO to ADO

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick Allison - 26 Dec 2003 15:47 GMT
Here's the DAO code.

 ' Set the default value for Record Add Date Time!!
 Set tdfTableDef = dbs.TableDefs!trelROLevelGroup
 tdfTableDef.Fields!RecordAddDateTime.DefaultValue = "=Now()"

Does anyone know where I can find how to convert this to ADO?

I've ready a little about OpenSchema but an example sure would help.

Thanks
Douglas J. Steele - 26 Dec 2003 16:49 GMT
Given that the DAO code works for you, why change it? Assuming you're
strictly dealing with Jet databases (i.e.: an MDB file), DAO is the better
method.

If you're determined, though, take a look into ADOX. However, also check
http://support.microsoft.com/?id=291194 as there can be problems trying to
set the default value.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

> Here's the DAO code.
>
[quoted text clipped - 7 lines]
>
> Thanks
Rick Allison - 26 Dec 2003 18:07 GMT
Douglas,

I need ADO really because DAO does not allow the use of "On Delete Cascade".
I am adding to a database that is scattered across the country.  I have used
DAO up until now but because of the limitation I have to switch.  It also
means that I can no longer support Access 97.  Not that it really matters
but it is a fact.

That's why I wanted to switch to ADO.  I've got it working with both. ADO to
do the "On Delete Cascade" and DAO to do the default value.

Is that the best way to go?

Rick
> Given that the DAO code works for you, why change it? Assuming you're
> strictly dealing with Jet databases (i.e.: an MDB file), DAO is the better
[quoted text clipped - 15 lines]
> >
> > Thanks
Douglas J. Steele - 26 Dec 2003 19:31 GMT
??? Whether you use DAO or ADO is completely unrelated to how referential
integrity works! Cascade Deletes are definitely supported in Access 97: I
work almost exclusively in Access 97, and I'm capable of supporting them
without any problems.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

> Douglas,
>
[quoted text clipped - 29 lines]
> > >
> > > Thanks
Steve Schapel - 26 Dec 2003 21:49 GMT
Doug,

Whereas setting Referential Integrity with Cascade Deletes enabled in
the Relationships Window is independent of libraries referenced, I
believe Rick is referring to running ALTER TABLE or CREATE TABLE
statements within VBA, and as such I believe this will not work with
DAO.

- Steve Schapel, Microsoft Access MVP

>??? Whether you use DAO or ADO is completely unrelated to how referential
>integrity works! Cascade Deletes are definitely supported in Access 97: I
>work almost exclusively in Access 97, and I'm capable of supporting them
>without any problems.
Douglas J. Steele - 26 Dec 2003 21:59 GMT
Thanks, Steve. I never use ALTER TABLE or CREATE TABLE, so you may be right.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

> Doug,
>
[quoted text clipped - 8 lines]
> >work almost exclusively in Access 97, and I'm capable of supporting them
> >without any problems.
TC - 27 Dec 2003 03:39 GMT
The OP is thinking as follows: "I don't know how to do it from DAO,
therefore, it can't be possible from DAO".

Oops!

TC

> Thanks, Steve. I never use ALTER TABLE or CREATE TABLE, so you may be right.
>
[quoted text clipped - 15 lines]
> > >work almost exclusively in Access 97, and I'm capable of supporting them
> > >without any problems.
Rick Allison - 28 Dec 2003 21:30 GMT
Steve,

Thanks for clarifying.  You are correct in what I want to do.

DAO does not support the "On Delete Cascade".  I can write code to handle
the delete of data but why when Referential Integrity does that for you
automatically.

For me the solution is to write ADO.  For now I have mixed ADO and DAO
because I still have not figured out how to manage the Default Value on an
existing column in a table via ADO (or ADOX, it that's the way).

Still looking.

Rick

> Doug,
>
[quoted text clipped - 10 lines]
> >work almost exclusively in Access 97, and I'm capable of supporting them
> >without any problems.
Douglas J. Steele - 29 Dec 2003 01:08 GMT
DAO may not allow you to specify "On Delete Cascade" in an ALTER TABLE or
CREATE TABLE statement, but you can still establish referential integrity
using DAO.

You do it by using the CreateRelation method, and setting the Attributes
parameter (the 4th parameter of the method) to dbRelationDeleteCascade.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

> Steve,
>
[quoted text clipped - 26 lines]
> > >work almost exclusively in Access 97, and I'm capable of supporting them
> > >without any problems.
Rick Allison - 29 Dec 2003 02:28 GMT
Doug,

I cannot thank you enough for this.  It would have taken me a long time to
find the CreateRelation method.

I'll be back to let you know how it goes.

Rick

> DAO may not allow you to specify "On Delete Cascade" in an ALTER TABLE or
> CREATE TABLE statement, but you can still establish referential integrity
[quoted text clipped - 36 lines]
> them
> > > >without any problems.
Rick Allison - 31 Dec 2003 18:03 GMT
Doug et. al.

What's the "db"Parameter to create an Autonumber field in a table?

I switched to TableDef to create tables on the fly but I cannot find how to
create an autonumber field.  Best I can find is to create an integer then a
unique index (primary key) but that's it.

Thanks,

Rick

> DAO may not allow you to specify "On Delete Cascade" in an ALTER TABLE or
> CREATE TABLE statement, but you can still establish referential integrity
[quoted text clipped - 36 lines]
> them
> > > >without any problems.
Douglas J. Steele - 31 Dec 2003 19:38 GMT
You create the Field as dbLong, and then you set its Attributes to
dbAutoIncrField:

Set fld1 = tdf.CreateField("ContactID", dbLong)
fld1.Attributes = fld1.Attributes + dbAutoIncrField

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

> Doug et. al.
>
[quoted text clipped - 51 lines]
> > them
> > > > >without any problems.
Rick Allison - 31 Dec 2003 21:03 GMT
Thanks again.  This really helps.  I am learning a lot!!

> You create the Field as dbLong, and then you set its Attributes to
> dbAutoIncrField:
[quoted text clipped - 64 lines]
> > > them
> > > > > >without any problems.
Tim Ferguson - 26 Dec 2003 21:25 GMT
> I need ADO really because DAO does not allow the use of "On Delete
> Cascade".

Check the properties of the Relationship object and the Relationships
collection.

You could also look at the ALTER TABLE command in SQL and read about the
CONSTRAINT clause.

Hope that helps

Tim F
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.