Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > Getting the record number of the record just added
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 13th April 07:35
bertman
External User
 
Posts: 1
Default Getting the record number of the record just added



Hello,

I use:
VB 6 sp5
Access 2000 database
DAO connection

I have the following problem. I add a new record in the database and in the
table is a Autonumbering field. I want to know that number.
For example

***
Set rs = db.OpenRecordset("T_Wedstrijd")
With rs
.AddNew
!Hoofdgroepnr = Hoofdgroepnr
!Teamnr = NeedNr(cmbTeam.Text)
!Tegenstander = txtTegenstander.Text
!Plaats = chkPlaats.Value
!Weeknr = txtWeeknr.Text
!Jaar = txtJaar.Text
!WedstrijdNr = txtWedstrijdnr.Text
.Update
End With
***

This works fine, but in the table 'T_Wedstrijd' is also a field call 'WedId'
this is a autonumber field. And after 'End With' I want that number back, I
can't compare the textfield in VB with the fields in this table because some
can be the same. So I need something uniek and that is 'WedId'.

Bert
  Reply With Quote


 


2 13th April 07:35
johan bechthum
External User
 
Posts: 1
Default Getting the record number of the record just added



Just read it before the End With :-)
The Autonumbering field if "filled" as soon as a record is added.

Set rs = db.OpenRecordset("T_Wedstrijd")
With rs
.AddNew
txtWedID.Text = CLng(!WedID)
!Hoofdgroepnr = Hoofdgroepnr
!Teamnr = NeedNr(cmbTeam.Text)
!Tegenstander = txtTegenstander.Text
!Plaats = chkPlaats.Value
!Weeknr = txtWeeknr.Text
!Jaar = txtJaar.Text
!WedstrijdNr = txtWedstrijdnr.Text
.Update
End With


Hope this helps.

Johan.


"Bertman" <Bertman@home.nl> schreef in bericht
news:bmgmnp$n6v$1@news1.tilbu1.nb.home.nl...


the

'WedId'

I

some
  Reply With Quote
3 13th April 07:35
robert berman
External User
 
Posts: 1
Default Getting the record number of the record just added


If the autonumber column is your identity column consider using
"SELECT @@IDENTITY"
  Reply With Quote
4 13th April 07:35
bertman
External User
 
Posts: 1
Default Getting the record number of the record just added


Hello Johan

Thnx for youre reply. And how easy can it be. Thnx

BErt


"Johan Bechthum" <JohanBechthum@hotmail.com> schreef in bericht
news:k7Wib.11034$P51.317904@amstwist00...

back,
  Reply With Quote
5 13th April 07:35
bertman
External User
 
Posts: 1
Default Getting the record number of the record just added


Hello Robert

Thnx for youre reply, but what do you mean with this:
"SELECT @@IDENTITY"
I never heard of it.

Bert


"Robert Berman" <ThornmastrNOSPAM@earthlink.net> schreef in bericht
news:cXWib.55605$mQ2.8682@newsread1.news.atl.earth link.net...
  Reply With Quote
6 13th April 07:35
robert berman
External User
 
Posts: 1
Default Getting the record number of the record just added


Bert,

For SQL Server (and Access with the Jet 4.0) drivers

SELECT @@identity FROM Table will get you the last inserted records
identity/autonumber
  Reply With Quote
7 13th April 07:35
tony m
External User
 
Posts: 1
Default Getting the record number of the record just added


The original poster was using DAO, which doesn't support the SELECT
@@identity method of retrieving the last inserted autonumber.

Tony
  Reply With Quote
8 13th April 07:35
robert berman
External User
 
Posts: 1
Default Getting the record number of the record just added


Whoops. I forgot the DAO comment. However, while I can certainly
understand the use of DAO with Jet 3 drivers, but, why use DAO using
Jet 4?
  Reply With Quote
9 14th April 15:35
tony m
External User
 
Posts: 1
Default Getting the record number of the record just added


Personally, I tend to stick with with DAO when doing Access projects,
because I've used it since Access 2/VB3 and I'm more comfortable
working with it. You are certainly right, however, about ADO being
more flexible when using Jet 4.

Tony
  Reply With Quote
10 14th April 15:35
robert berman
External User
 
Posts: 1
Default Getting the record number of the record just added


Tony,

Like you, I have used DAO since ACCESS 2. If it was not for the
stupidity of M$ I would probably still be happily using DAO. But, when
Bill decided to take JET out of active development, I had clients
begging to rewrite applications using a JET backend to using MSDE
backends. This has become for me what the turn of the century fiasco was
for banking consultants.

Robert
  Reply With Quote


 


Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Development, Ada, Apple script, Assembler, Awk, Beos, Basic, C, C++, C#, C# .net, .net, .net frameworks, Asp .net, Clarion, Clipper, Clos, Clu, Cobol, Coldfusion, Delphi, Dylan, Eiffel, Forth, Fortran, Haskell, Hermes, Icon, Idl, Java, Java script, Jscript .net, Jcl, Linoleum, Lisp, Lotus, Limbo, Logo, Ml, Mumps, Oberon, Postscript, Pop, Pl1, Prolog, Python, Ruby, Pascal, Perl, Php, Rebol, Rexx, Sed, Sather, Scheme, Smalltalk, Tcl, Vhdl, Vrml, Visual basic, Visual basic .net, Yorick, Mysql, Omnis, Postgresql, Xbase, Access, Oracle, Adabas, Berkeley, Btrieve, Filemaker, Gupta, Db2, Informix, Ingres, Mssql server, Object, Olap, Paradox, Rdb, Revelation, Sybase, Theory, Dbase, Html, Java script, Css, Flash, Photoshop, Corel script, Xml, Tech, Beos, Gem, Hp48, Hpux, Linux, Mac, Ms-dos, Os2, Palm, Solaris, Ti99, Windows, Xenix, Aos, Chorus, Geos, Inferno, Lantastic, Lynx, Mach, Minix, Netware, Os9, Parix, Plan9, Psos, Qnx, Xinu, Sco, Unix, Aix, Aux, 386bsd, Bsdi, Freebsd, Netbsd, Openbsd, Ultrix, Amd, Intel, Aptiva, Buz, Deals, Homebuilt, Overclocking, Programming, Extra forums


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666