473,791 Members | 3,071 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing Access mdb via ODBC - how to return autonumber

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 #1
33 7645
rkc
Steven Taylor wrote:
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?


Your best option is to retrieve the record using whatever real fields
make the record unique. That should never be a counter.
Nov 13 '05 #2
rkc
Steven Taylor wrote:
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?


Your best option is to retrieve the record using whatever real fields
make the record unique. That should never be a counter.
Nov 13 '05 #3

And why not? I use the dmax() function inserted in nz()

=nz(dmax(...))+ 1

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 #4

And why not? I use the dmax() function inserted in nz()

=nz(dmax(...))+ 1

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 #5

You can use the Select Mas--------------- query. Put text field on the form
or sub form showing the Max Count. This "lets call it the total Textbox", wil
always show a total count. After updating from insert statement. Refresh the
textbox. This will show the new count. Hope this useful.

Doug
lo******@sbcglo bal.net

Steven Taylor wrote:
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.

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #6

You can use the Select Mas--------------- query. Put text field on the form
or sub form showing the Max Count. This "lets call it the total Textbox", wil
always show a total count. After updating from insert statement. Refresh the
textbox. This will show the new count. Hope this useful.

Doug
lo******@sbcglo bal.net

Steven Taylor wrote:
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.

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #7
>>
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".

Steve.

Nov 13 '05 #8
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.
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?


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've done it in the past with batch inserts using a temp table. I
reserved the value -1000000 as the value for a particular non-unique
field, and made that the default value. When I inserted a batch of
records, I could then retrieve them by that value in that field.
When I'd processed them, I'd clear the field to Null.

It worked pretty well because it wasn't a multi-user application.

You could do the same thing in a multi-user application by using a
user-stamp in the record in conjunction with the dedicated field
that indicates it's a new record.

All of those are kludges for use when you don't have the capability
to do a cursor-based record add (i.e., in a recordset).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #9
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

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.

Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
8296
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;" _
3
2306
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...
9
3053
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...
42
5656
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?
4
2748
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,
0
511
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...
6
13999
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'
15
4742
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...
1
2448
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
0
9669
marktang
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...
0
9515
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,...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
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...
0
6776
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();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.