473,466 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

manually updating text box causes primary key problems

26 New Member
I have a form that has several subforms on it. They are all linked to the main table by use of a field called Patient ID.
On this form, if I use the buttons for first record, previous record, next record, last record; there is no problem and everything works correctly.
But if I try to type in an ID number in the box and then hit tab, it gives me the following dialog box.

"The changes that you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain the duplicate data, remove the index, or redefine the index to permit duplicate entries and try again."

I think that it's trying to change the Patient ID of the current patient to whatever number i type in, and it can't because the ID is the primary key. But i don't know how to fix this.

Or if there's a different way to ensure that the user cannot enter duplicate values in the ID field, that works too.

Appreciate the help, Joe.
Apr 1 '11 #1

✓ answered by Rabbit

You have to create an unbound text box and in the after update event of that box, find and goto that record.

9 2108
Rabbit
12,516 Recognized Expert Moderator MVP
I think that it's trying to change the Patient ID of the current patient to whatever number i type in, and it can't because the ID is the primary key. But i don't know how to fix this.
That's exactly what it's trying to do. There's nothing to fix because that's what it's supposed to do if you try to change the value of a unique field to an existing value.
Apr 1 '11 #2
Joe Farage
26 New Member
Ok that makes sense, but then how do I set it up so that the user can type in a number and that record will load? without changing any other records or removing the primary key?
Apr 1 '11 #3
Rabbit
12,516 Recognized Expert Moderator MVP
You have to create an unbound text box and in the after update event of that box, find and goto that record.
Apr 1 '11 #4
Joe Farage
26 New Member
ok so i got that to work, and i still want to have buttons that will go to the next,prev, last, first, etc. records. I've already set up the buttons so that the first one goes to record 1, and next and previous go to their records (prev also gives a message box if it's already at record 1). how do i set up the Last button and get a message box for the Next button if it's already at the last record?
Apr 1 '11 #5
Rabbit
12,516 Recognized Expert Moderator MVP
A recordset's .bof and .eof properties will tell you if you're at the beginning or end respectively.
Apr 2 '11 #6
NeoPa
32,556 Recognized Expert Moderator MVP
I have found, when trying similar record navigation logic, that there are certain things that don't work as I would expect them to (I hesitate to say Access has it wrong, as we see that so many times in questions on here and 99 times out of 100 the poster is simply illustrating their own lack of understanding - so I think it's wrong, but there may just be a reason I'm not seeing).

Anyway, the code snippet below shows what I came up with and comments why certain (non-intuitive) choices were made. I hope this helps.

Expand|Select|Wrap|Line Numbers
  1. Select Case intKeyCode
  2. Case vbKeyUp
  3.     'Bug where .AbsolutePosition can be 0 even when on NewRecord
  4.     If (.Recordset.AbsolutePosition > 0) _
  5.     Or (.NewRecord) Then _
  6.     Call DoCmd.GoToRecord(Record:=acPrevious)
  7. Case vbKeyDown
  8.     'No reliable way to determine if we're already on the last record.
  9.     On Error Resume Next
  10.     If Not .NewRecord Then Call DoCmd.GoToRecord(Record:=acNext)
  11.     On Error GoTo 0
  12. Case vbKeyHome
  13.     Call DoCmd.GoToRecord(Record:=acFirst)
  14. Case vbKeyEnd
  15.     Call DoCmd.GoToRecord(Record:=acLast)
  16. End Select
PS. I'm open to others' suggestions on ways to handle this better myself. I find it hard to believe that such clumsy code is the best available, but nothing else I tried worked for me. I'm using Access 2003.
Apr 2 '11 #7
NeoPa
32,556 Recognized Expert Moderator MVP
Just to be clear, I did try looking at the values of Me.Recordset.EOF and Me.Recordset.BOF (For the Last and First records respectively), and neither showed as TRUE in either circumstance. That was one of the issues that I struggled with when I first developed this code.
Apr 2 '11 #8
OldBirdman
675 Contributor
One of my pet peeves is to have a button which, when pressed, gives a message saying "You can't do that now". Not only have I gone to the effort of selecting and pressing the button, but I must now press "OK" to clear the error message. Hopefully, I don't forget which button I had selected, and select it again.

I'm using Access 2003, and if I open any table in 'datasheet' view, I will have a set of navigation controls at the bottom left of that view. The same buttons, actually, that Access will supply if I set a form's properties to have navigation buttons.

Notice that the Next and/or Previous buttons are greyed out (Enabled=False) if necessary. I cannot display the Previous record if there isn't one. I can display the First record if I am at the first record, and my brain does has trouble with that. Maybe because I think of it as "GoTo First Record" and I can't 'Go' anywhere, but Access thinks of it as "Display First Record" which can be done even if already being displayed. "Next"/"Last" are not so neat as the "Add New" is sort of put between the last record and the end-of-file, but that is another issue.

NeoPa's code snippit appears to be part of a common function called when a navigation button/key is pressed. I would call a common function after the button/key is pressed and the navigation is complete. This would (dis-)Enable appropriate navigation buttons. I would also call this same function from any other function that affected navigation, such as an "Add New", "Delete Current", or ReQuery.

Admittedly, this line of logic is somewhat more time-consuming to set up. Because I usually use this type of logic, I have several "Tidy..." functions other than "TidyNav". I feel this makes my forms more intuitave, and therefore subject to fewer user errors.

Navigation is too important not to give it extra attention. Locating and displaying a desired record is what most users do.
Apr 2 '11 #9
NeoPa
32,556 Recognized Expert Moderator MVP
Some very good points there OB, most of which I agree with wholeheartedly, and none of which do I disagree with (Ambivalent on a couple maybe).

I feel I should state, for the record and to ensure anyone using the same code knows what they're letting themselves in for, that I don't use buttons for record navigation. I use keystrokes instead. Buttons, if they were to be used, should be greyed out when inactive in my view too (where possible of course). As this concept is not appropriate for keystrokes there is nothing in my code to support that.
Apr 3 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bob Kaku | last post by:
I'm trying to create a text editing and updating capability to help someone who wants to maintain content on a web page without having to know any HTML or use a web authoring tool and FTP'ng the...
0
by: me | last post by:
I have been using VS.NET since beta 1 and currently get about 1-2 IDE lockups/crashes a week. since using CrystalReports.NET for the first time 2 days ago i am getting IDE problems faster than 1...
4
by: Peter Scott | last post by:
I created a table that has a column in that needs to contain a full Unix file path. Since 2048 was too long for a VARCHAR, I made it TEXT. I since populated the table. Now I want to make the...
2
by: Jeff S | last post by:
No question here; just information that anyone running ZoneAlarm on a development machine may find useful as you develop your ASP.NET apps - (or for those of you who are assisting users who may be...
14
by: multiformity | last post by:
So I have been working on an opensource project for a while, and decided to really try to make it look better after focusing on the functionality most of this time. Up to now, I have simply used a...
1
by: Hansen | last post by:
Hi, I'm making a translation thingie, that contains several languages. One of them is Danish and in one of my update scripts, I've come upon something strange. I have a text containing the...
2
by: cccompton via DBMonster.com | last post by:
Greetings all. We recently upgraded from DB2 v8.2 to 9.1 FP1 and tested the AUTO_REORG functionality. As recommended by SAP, we scheduled the job REORGCHK_ALL weekly. This spews out an error...
9
by: Marianne160 | last post by:
Hi, I know there are various answers to this problem available on the web but none of them seem to work for me. I am using Access 2003 to make a form to look up data from a table. I have so far...
4
by: parkergirl | last post by:
Hello, I am currently working on a project that has many tabs all on one form. Since you can only have so many controls on one form, my job is to seperate these tabs into forms. One problem that I...
2
by: Eric | last post by:
Hi, There is a textbox which contains some text. The purpose is to update the text manually into the textbox and send (update) the updated text to the database. My problem is that when i...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.