Hope someone can help. This is half an Access question. The half I'm
using is Access Xp as a backend data file. I'm using ODBC to connect
to the data file. All commands are via SQL type statements (SELECT,
UPDATE & INSERT INTO). (I'm using/trialling Realbasic as a frontend).
After inserting a record (row) into a table using "INSERT INTO ...."
what is the easiest way to obtain the value of a counter field for the
record just inserted?
I have considered "SELECT Max(CounterFiel d) FROM ....". By using ODBC
is this my only option in retrieving the counter field value?
Thanks in advance.
Steven Taylor
Melbourne, Australia.
Nov 13 '05
33 7650 DAO/JET has lotsa new stuff; its champions don't seem to mention this new stuff. Is there something wrong with it? OHHHHHHHH ... maybe it can't be used in ODBC? I never use ODBC so I don't know. (Maybe !!!!!!NEW!!!!!! is bad; "We don't want people like YOU around here, Mister; better ride on outta here"). No REALLY ... it's JUST "SELECT @@IDENTITY" ... no table name required.
Yes I am old. No I am not confusing JET with MS-SQL. Yes, someone woke me up. No, I can't go back to sleep.
Thanks for that, just tried "SELECT @IDENTITY" and it worked. I now
have to get my head around why it worked, if one is not specifying a
table name. I'm assuming that after every "INSERT INTO...." the very
next line is "SELECT @@IDENTITY". Are there any multi-user issues
here? Access help really doesn't help and the only reference to
@@IDENTITY is at 'SQL Data Types' help page and that is very sparse.
Steve.
Thanks David,
I've inserted some comments inline
David W. Fenton wrote: Steven Taylor <ne******@super jacent.net> wrote in news:42******** *************** @news.optusnet. com.au:
Hope someone can help. This is half an Access question. The half I'm using is Access Xp as a backend data file. I'm using ODBC to connect to the data file. All commands are via SQL type statements (SELECT, UPDATE & INSERT INTO). (I'm using/trialling Realbasic as a frontend).
Can Realbasic use DAO? If it can, then you can use your data via Jet, and then use a DAO append-only recordset to insert the record, read the new Autonumber value, then use that to retrieve the finished record.
I am comfortable with DAO from within Access. Outside of Access,
Realbasic for instance, I'm not too sure. I am now showing some of my
ignorance here, but what the heck, here goes. Realbasic can access
ActiveX objects, does that mean then that ultimately DAO is available to
me. I know Realbasic hooks into (or can use) ADO but I haven't
trialled it or used it. Even in Access I don't use ADO because I'm so
familiar with DAO.
snip
If you can't do it with DAO, and there are no ODBC methods that work the same way (i.e., returning a recordset and inserting the new record in the recordset, rather than through a SQL INSERT), then you are forced to do something like having a field in the table dedicated to holding data to uniquely identify the record. You'd insert your record with this unique value, then immediately retrieve the new record based on that one field, grab the Autonumber value and then set the field you'd used to indentify the inserted record to Null.
I like this idea, it makes sense.
Steve.
Steven Taylor <ne******@super jacent.net> wrote in
news:42******** *************** @news.optusnet. com.au: David W. Fenton wrote: Steven Taylor <ne******@super jacent.net> wrote in news:42******** *************** @news.optusnet. com.au:
Hope someone can help. This is half an Access question. The half I'm using is Access Xp as a backend data file. I'm using ODBC to connect to the data file. All commands are via SQL type statements (SELECT, UPDATE & INSERT INTO). (I'm using/trialling Realbasic as a frontend).
Can Realbasic use DAO? If it can, then you can use your data via Jet, and then use a DAO append-only recordset to insert the record, read the new Autonumber value, then use that to retrieve the finished record.
I am comfortable with DAO from within Access. Outside of Access, Realbasic for instance, I'm not too sure. I am now showing some of my ignorance here, but what the heck, here goes. Realbasic can access ActiveX objects, does that mean then that ultimately DAO is available to me. I know Realbasic hooks into (or can use) ADO but I haven't trialled it or used it. Even in Access I don't use ADO because I'm so familiar with DAO.
I don't know what RealBasic can and can't do. The methods for using
DAO ought to be pretty similar to setting up your RealBasic app for
using ADO, but that's just speculation on my part.
"Can access ActiveX objects" may mean "can use COM," and if so, then
DAO ought to work, too. If you can't do it with DAO, and there are no ODBC methods that work the same way (i.e., returning a recordset and inserting the new record in the recordset, rather than through a SQL INSERT), then you are forced to do something like having a field in the table dedicated to holding data to uniquely identify the record. You'd insert your record with this unique value, then immediately retrieve the new record based on that one field, grab the Autonumber value and then set the field you'd used to indentify the inserted record to Null.
I like this idea, it makes sense.
It's a kludge and I would do it the other way if you can.
--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
"ly******@yahoo .ca" <ly******@yahoo .ca> wrote in
news:11******** **************@ f14g2000cwb.goo glegroups.com: Assuming you are using the latest DAO-JET have you tried something like:
Sub temp() Dim rst As DAO.Recordset With DBEngine(0)(0) .Execute "INSERT INTO TABLE1 ([VALUE], IDS) VALUES ('c', 5)" Set rst = .OpenRecordset( "SELECT @@IDENTITY") End With Debug.Print rst.Collect(0) ' shows 7 the last auto number of the last table updated Set rst = Nothing End Sub
Well, that's very cool. Jet 4 really was a major upgrade in many
ways, and it seems to me that a lot of those advances got lost in
the ADO folderol and in all the problems with the very unstable
initial releases of Jet 4 (6 service packs before it was stable).
DAO/JET has lotsa new stuff; its champions don't seem to mention this new stuff. Is there something wrong with it? OHHHHHHHH ... maybe it can't be used in ODBC? I never use ODBC so I don't know. (Maybe !!!!!!NEW!!!!!! is bad; "We don't want people like YOU around here, Mister; better ride on outta here").
Well if ODBC won't do the job I suppose you could use ADO on top of OLEDB. It's soooooooooooooo complicated.
With CurrentProject. Connection .Execute "INSERT INTO TABLE1 ([VALUE], IDS) VALUES ('c', 5)" Debug.Print .Execute("SELEC T @@IDENTITY").Co llect(0) ' shows 8 the last auto number of the last table updated End With
I suppose you will have to create your own connection if you are working in ODBC. This is at least 30 seconds work.
Well, now I see why those MS insiders recommend against ADO. You can SEE how much more miserable the ADO is. No setting object pointers. Cleans up its own garbage ... eek it's awful. And I bet it's only 99.973 % as fast. WAIT ... against ODBC ... who knows ... maybe 99.974?
No REALLY ... it's JUST "SELECT @@IDENTITY" ... no table name required.
Yes I am old. No I am not confusing JET with MS-SQL. Yes, someone woke me up. No, I can't go back to sleep.
Where to you find out about these little additions to Jet 4?
I really wanted to use A2K when it came out (in large part because
of the vast improvements in Jet 4 replication), but there were so
many problems with A2K as a development platform that it wasn't
worth it.
I now support clients on A97, A2K and A2K3 (I had a one-time client
with A2K2), and don't really program much in A2K because it feels
like working with one hand tied behind my back. Perhaps if I worked
in A2K all the time, I'd have discovered more of the new features of
Jet 4, but the price in programming productivity and instability
seems to me to not at all be worth the tradeoff.
--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Steven Taylor <ne******@super jacent.net> wrote in
news:42******** **************@ news.optusnet.c om.au: DAO/JET has lotsa new stuff; its champions don't seem to mention this new stuff. Is there something wrong with it? OHHHHHHHH ... maybe it can't be used in ODBC? I never use ODBC so I don't know. (Maybe !!!!!!NEW!!!!!! is bad; "We don't want people like YOU around here, Mister; better ride on outta here"). No REALLY ... it's JUST "SELECT @@IDENTITY" ... no table name required.
Yes I am old. No I am not confusing JET with MS-SQL. Yes, someone woke me up. No, I can't go back to sleep.
Thanks for that, just tried "SELECT @IDENTITY" and it worked. I now have to get my head around why it worked, if one is not specifying a table name. I'm assuming that after every "INSERT INTO...." the very next line is "SELECT @@IDENTITY". Are there any multi-user issues here? Access help really doesn't help and the only reference to @@IDENTITY is at 'SQL Data Types' help page and that is very sparse.
It works for the same reason .RecordsAffecte d works in the same
conditions -- it's a property of the database object (in DAO)
/connection (in ADO) you've just used. So, no, there shouldn't be
any multi=user issues, unless you have multiple forms adding records
in your front end using a single DAO database variable or the ADO
default connection. Since DAO database objects and ADO connections
cannot be shared between users, there are no multi-user issues.
Before Jet 4, the identity value was not available, though that was
commonly available when using ODBC with server database back ends.
It's a very useful thing to have now in Jet 4.
Too bad so few of my clients use Jet 4 back ends.
--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Steven Taylor wrote: I have considered "SELECT Max(CounterFiel d) FROM ....". By using ODBC is this my only option in retrieving the counter field value?
Your best option is to retrieve the record using whatever real fields make the record unique. That should never be a counter.
Unfortunately this is not possible at the moment as I'm dealing with an existing system.
Could you elaborate on your comment regarding "Unique field, should never be a counter".
A counter, usually refered to as an autonumber when using Access/Jet,
is used to uniquely identify a record. It should not be used to make
the data in that record unique. That should come from a combination
of values in fields (not generated by the db engine) that is only ever
allowed to occur once in a table. That is the heart and soul of a
relational database. Could you elaborate on your comment regarding "Unique field, should never be a counter".
A counter, usually refered to as an autonumber when using Access/Jet, is used to uniquely identify a record. It should not be used to make the data in that record unique. That should come from a combination of values in fields (not generated by the db engine) that is only ever allowed to occur once in a table. That is the heart and soul of a relational database.
I'll have to disagree with you on this one. You even mention "A
counter.....is used to uniqely identify a record". Without the use of
a single field (primary key) to identify a record, creating a 'many to
many' type relationship would be a nightmare. The joining table
(linking table) rather than having a minimun two foreign key fields
would require as many combined fields from each of the primary tables.
I'm not suggesting though, that every table must have a counter as a
primary key, just that it makes it so much simpler to work with if one
is present, if it's going to be related to.
I suppose it comes down to personal preference.
Steve.
Steven Taylor wrote: Could you elaborate on your comment regarding "Unique field, should never be a counter". A counter, usually refered to as an autonumber when using Access/Jet, is used to uniquely identify a record. It should not be used to make the data in that record unique. That should come from a combination of values in fields (not generated by the db engine) that is only ever allowed to occur once in a table. That is the heart and soul of a relational database.
I'll have to disagree with you on this one. You even mention "A counter.....is used to uniqely identify a record". Without the use of a single field (primary key) to identify a record, creating a 'many to many' type relationship would be a nightmare. The joining table (linking table) rather than having a minimun two foreign key fields would require as many combined fields from each of the primary tables.
I'm not suggesting though, that every table must have a counter as a primary key, just that it makes it so much simpler to work with if one is present, if it's going to be related to.
I suppose it comes down to personal preference.
I agree.
In one of my databases, a hierarchy goes like this (usually 1:n)
Project->Order->OrderItem->ExpeditingComp onentSplit->DelSplit->MMTItem[1]->MRRItem[2]
Can you imagine the PK on MRRItem if I didn't use a counter?
ProjectNo + OrderNo + OrderItemNo + CompSplit + DelSplit + MMTNo + MRRNo
The items in stock have an audit trail to issue and installation,
Material Control would be an absolute nightmare.
[1] MMT = Material Movement Ticket
[2] MRR = Material Receiving Report
--
[OO=00=OO]
On Tue, 19 Jul 2005 08:59:48 +0100, Trevor Best <no****@besty.o rg.uk> wrote: Steven Taylor wrote: Could you elaborate on your comment regarding "Unique field, should never be a counter".
I agree.
etc
I think the point being made isn't "don't use a counter", it is that two records shouldn't
be exactly the same apart from the counter
rude person wrote: On Tue, 19 Jul 2005 08:59:48 +0100, Trevor Best <no****@besty.o rg.uk> wrote:
Steven Taylor wrote:
>Could you elaborate on your comment regarding "Unique field, should >never be a counter".
I agree.
etc
I think the point being made isn't "don't use a counter", it is that two records shouldn't be exactly the same apart from the counter
Yes. Exactly that. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eric E |
last post by:
Two questions regarding ODBC.
1) I am connecting to a MySQL database using the following code:
Function LoginToMySQL(sUsername As String, sPW As String) As Boolean
Dim dbMySQL As Database
Dim cnMySQL As DAO.Connection
Dim sDSN As String
sDSN = "ODBC;DRIVER={MySQL ODBC 3.51 Driver};" _
& "SERVER=127.0.0.1;" _
|
by: Mike |
last post by:
Using MS Access XP standard install (no Jet or MDAC updates applied
yet) as front end, MySQL 4.0 as backend and MySQL ODBC connector
version 3.51.
When pasting multiple records into the database either in a form or
directly in the table, all records / fields display #deleted in each
column. This only happens when pasting multiple records, if a
single record is pasted, the #deleted comment does not appear. When
I refreash the view, the...
|
by: Paradigm |
last post by:
I am using an Access2K front end to a MYSQL database. If I enter a new
record in a continuous form the record appears as #deleted as soon as I move
to a different record in the form until I requery the form. After the
requery the records are in different order to the order that they may be
entered in.
The record does not seem to be assigned an ID (autonumber ID field) until
after it is requeried.
My problem is that after requerying the...
|
by: PC Datasheet |
last post by:
I have zero experience with using a SQL database for a backend and Access
for a frontend. I have some questions:
1. Does an SQL database have tables?
2. How does Access connect to the data in an SQL database? Linking,
importing, or ???
3. Earlier today there was a thread regarding DAO and ADO. In the thread it
was said that ADO is very useful when the backend is a SQL database. Could
someone explain that?
|
by: David Siroky |
last post by:
Hi!
I'm trying to connect to a MDB file via ODBC like this:
char *DSN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\dev-cpp\\test\\1.mdb";
SQLAllocEnv(&env);
SQLAllocConnect(env, &hdbc);
SQLBrowseConnect(hdbc,
(UCHAR*)DSN,
| |
by: Steven Taylor |
last post by:
Hope someone can help. This is half an Access question. The half I'm
using is Access Xp as a backend data file. I'm using ODBC to connect
to the data file. All commands are via SQL type statements (SELECT,
UPDATE & INSERT INTO). (I'm using/trialling Realbasic as a frontend).
After inserting a record (row) into a table using "INSERT INTO ...."
what is the easiest way to obtain the value of a counter field for the
record just...
|
by: Andy Barber |
last post by:
Hi,
I'm trying to write an app that reads data from a table
into a string variable for later use in my program.
Below is a snippet of the code I'm using, which compiles
ok, but at runtime I get and error 'Object reference not
set to an instance of an object.' as soon as I try to
access the data in the fields, I.e. at the line that
reads 'KeyFlags(i) = rstFields("keyflag").value'
|
by: Marcus |
last post by:
I created a VB.Net 1.1 application that iterates through all the tables
in any basic Access 2000 database passed to it and generates the same
table structure in a SQL Server Express database. The structure is
created fine (with minor data conversions from one to the other, e.g.
yes/no --> bit, memo --> text, etc). My problem now is transferring the
data over from Access to SQL Server. I thought it would be a fairly
straight forward...
|
by: gordon.dtr |
last post by:
Hi,
Has anyone had this problem ?
I am using MySQL ODBC 3.51 Driver, with MS Access 2003 and MySQL 4.1.11
standard log.
I created my tables in MS Access, then exported them via ODBC to an
externally hosted MySQL database (fasthosts) . I then import-linked
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |