dbTalk Databases Forums  

Can't set primary key

comp.database.ms-access comp.database.ms-access


Discuss Can't set primary key in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
moose
 
Posts: n/a

Default Can't set primary key - 06-03-2004 , 11:17 AM






We have a VisualBasic application for our field personnel that stores
data in an MS-Access database. When they come out of the field their
individual databases are read and added to the master database. We
are no longer using Autonumber since it started generating existing
keys. The lead table in the master database has a primary key of type
Number. When adding a new record I use the AddNew method. I obtain
the current time and convert it to a double. Then I set the primary
key id to this value. But it doesn't stick. My MsgBox shows it as 0.

Dim sPK As String
Dim dPK As Double
sPK = Format(Date(), "yyyymmdd") & Format(Time(), "hhnnss")
dPK = CDbl(sPK)

Reply With Quote
  #2  
Old   
Gary Floam
 
Posts: n/a

Default Re: Can't set primary key - 06-03-2004 , 03:41 PM






Try PrimaryKey = nz(dmax("PrimaryKey",Table),0) + 1

Hope this helps,

Gary

"moose" <sky_diver_ (AT) excite (DOT) com> wrote

Quote:
We have a VisualBasic application for our field personnel that stores
data in an MS-Access database. When they come out of the field their
individual databases are read and added to the master database. We
are no longer using Autonumber since it started generating existing
keys. The lead table in the master database has a primary key of type
Number. When adding a new record I use the AddNew method. I obtain
the current time and convert it to a double. Then I set the primary
key id to this value. But it doesn't stick. My MsgBox shows it as 0.

Dim sPK As String
Dim dPK As Double
sPK = Format(Date(), "yyyymmdd") & Format(Time(), "hhnnss")
dPK = CDbl(sPK)
.
.
.
rsM0.AddNew
rsM0!pkg_id = dPK
.
.
.
rsM0.Update
MsgBox("pkg_id=" & rsM0!pkg_id)

Would someone please show me how to set the primary key without using
AutoNumber.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.