473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Help editing a record from form textbox field

New to creating forms in access...

I have made a form to add new records that opens in full screen. The first textbox on the form is my DB Primary Key. When I enter a value that is already in my DB, I get a message "can't add data because it would create a duplicate". I understand why I am getting the message, but should I not be able to edit an existing record in this same form? If not, how can I do this?

The Property Sheet for the form I have created is set to "Yes" for Data Entry, Allow Additions, Allow Deletions, and Allow Edits. Record Locks is set to "No Locks".
Feb 16 '14 #1
9 2761
zmbd
5,501 Expert Mod 4TB
Is the form bound to the record-set?
Sounds as if it is not and that you have code behind the scenes saving the record; however, you've not provided that information.

If it is bound, and you alter the primary key and attempt to save, then the error is by design. You have to move the form to the record to edit, change the fields of interest and then save.

If the form is unbound and you are using code to save the fields then do not save the edited primary key, you need to open the the record for editing. The error in your code cannot be resolved until you post your code.

PLEASE
Do NOT attach your database
Follow this link > Before Posting (VBA or SQL) Code
Feb 16 '14 #2
NeoPa
32,556 Expert Mod 16PB
John,

It seems you need to make your own mind up first about what you want the form to do for you. At one stage you say you want the form to add new records, yet later you wonder that it doesn't enable you to edit existing ones.

Well done for including the properties. One is particularly relevant. The .DataEntry property specifically restricts the form from editing existing records. Even with that reset though, a form will not navigate to a record at the point (which you describe) of entering the data unless you put specific code in there to tell it to do that. I wouldn't advise that, as it would be confusing for users. They expect values entered onto the form to update any existing values. Not to be interpreted as a request to select a different record.

To select a specific record, you can either filter to cause the record to show or navigate to the record. See Example Filtering on a Form for the filtering side. Filtering can be general or specific. IE. Matching a pattern or a specific value, including that of a unique index.
Feb 16 '14 #3
zmbd, it is a bound form. There is no code there.

NeoPa, you are correct on making my mind up. When I created the form, I just wanted to add records. Once I got it up and going, I realized I need to edit records also. All I really want the form to do is add a record if it doesn't exist. If it does exist, when I put a value in the first field of the form, I would like for it to show the values in my textboxes and allow me to edit them, just as I can do in a table. I would like to at least be able edit the primary key, even if I have to retype other related textboxes. If it were for me I'd just use the table (I'm having to do that now when I have a value that needs editing), but I have other users that will be using the DB.
Feb 16 '14 #4
NeoPa
32,556 Expert Mod 16PB
CQLJohn
"I would like for it to show the values in my textboxes and allow me to edit them, just as I can do in a table."

You are mistaken. What you do using a table is analogous to what a form does. You simply don't appreciate the first step as it is so automatic.

If you are on the new record of a table and type in an existing index value it does not navigate you to the matching record. On the contrary, it does exactly what the form was doing. It reports the error.

Being an intelligent human, though, what you actually do in the table is you first determine which record to start with. For a new record it will be at the bottom and for an existing one it will be where that one currently exists in the list. This is the part that you've overlooked as it's so simple when done by the human brain. This is what I was suggesting you duplicate in code by allowing the operator first to select the item they're interested in.

Once you (the VBA code) understand where the operator wants to work you can make that happen for them. Simples!
Feb 16 '14 #5
zmbd
5,501 Expert Mod 4TB
. I would like to at least be able edit the primary key, even if I have
Normally, one would not alter the primary key:
> Database Normalization and Table Structures.
Feb 16 '14 #6
zmbd, Agreed. I'm not actually wanting to edit the PK, just edit the fields associated with it.

NeoPa, I read the link. Me will have to think on it as I have little VBA skills. I did d/l your example, and I could probably make it work similar to that. Since I can't understand all of the code, I'll have to do a little training to break it down to make it work for me. It would be nice if one could enter a value in a textbox, have it checked to see if it exist and allow the record to be edited, if does not exist, add the record. That's my end goal (I think).
Feb 16 '14 #7
NeoPa
32,556 Expert Mod 16PB
CQLJohn
"That's my end goal (I think)."

May I suggest you think again. I see how that would be nice, but it would actually be counter-intuitive for the operator. It's not how things normally work, for various good reasons. It may work for this limited situation, but then when you want to do something similar but different, where it would be inappropriate, you are left with an expectation of similarity which you couldn't sensibly fulfil.

I recommend you look at a separate control that is used to specify the record you want to work on. This covers existing as well as new records. From there enter the rest of the data.

Whenever I filter on an exact match for any field I make sure the .DefaultValue for the related control is set to the filtered value. This can make data entry easier for the operator and brings the functionality very close to what you hope to do.
Feb 16 '14 #8
NeoPa, I haven't told you the whole story on the DB, just what I thought was important for what I needed.
What I am using it for is to add records for a lab.
I have different forms for each test.
The first 12 fields are the same on each form (item information).
Most of the time we only do one test per item (The DB is working for this).
We could do up to 10 or so tests on the same item (MY problem).
We would rarely have the results for more than one test at a time for an item.
I have the forms updating the appropriate fields in the DB.
When I say I want to edit a record, I'm not actually wanting to change any existing info, but add new test data with the use of a different form.
The people working for me are not too computer savvy, so I wanted to keep it in one format, with all the forms looking the same, so it's just a repetitive thing they have to do, no thinking about what to do.
I know this is not the idea way to do this, but I think it would just be real user friendly for my users.

Imagine getting a list of 50 items that need to be entered in the DB. There is no way to know if one of them has been tested and entered already under a different test method (which would cause a record lock). You wouldn't want to have to do a search on each item before you entered them. I don't really want them typing data that is already in the DB (item info). I want them to type the item number (my PK), tab to the next field (beforeupdate), if the record doesn't exist, write it. If the record exist, allow me to edit it. The edit would actually allow me to update new info in field non populated in the DB.

I'm sure there is a better way, but again, I'm a newbie...
Feb 16 '14 #9
NeoPa
32,556 Expert Mod 16PB
John, you seem to be saying one thing in one sentence and another in the next. Easily done when describing logic.

I understood you to be saying that you only ever enter new records. However, at no point do you explain you have separate tables for the items and the tests. Without this laid out clearly your explanations make little sense in any reliable way.
Feb 17 '14 #10

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

Similar topics

0
by: htmlgeek | last post by:
I've beaten my head againts this for two weeks and would appreciate any help. Am running Dreamweaver 2004 MX asp pages with MS Access 2000 and then 2003 and received same problems! I've rebuilt...
4
by: morgan.mark | last post by:
I am not an expert at access and I need a little help with a form. I have a form that is linked to a table with address information. My form has a checkbox linked to a field in the database to show...
2
by: Leon Shaw | last post by:
What is the best way (or How) to format a form textbox field so that when the user is entering data the text don't move (like it's trying to adjust itself or something) around?
2
by: donnet | last post by:
Inside my .aspx file, I have a textbox populated with data from a dataset like this: <asp:TextBox text='<%# DataBinder.Eval(Container.DataItem, "Comment")%>' id="CommentText" runat="server"...
2
by: danparks | last post by:
I understand how to use ASP to retrieve a value from a form textbox. I don't understand how to use ASP to fill in a value in a form textbox. I'm guessing that perhaps Response.Write can be used? If...
1
by: alex.gruenther | last post by:
I am new to Access and need help creating an edit record form. I've got a table called Player with attributes like name, address, phone, etc. I've created an edit player form with a combo box...
1
by: almurph | last post by:
Hi everyone, Is it possible to make a new events for a Web-form textbox. What I mean to ask is that I want an event to fire everytime a user enters a letter into a Web-form textbox. The only...
2
by: Richard | last post by:
Help please. I am trying to autofill a form text field from a select-box lookup. I have no problem doing this if the select-box is part of the form but because there are 5 possible select boxes...
9
by: keydrive | last post by:
There must be a difference between a standard input field and a textbox field. I would like to use a textbox field and save the value in a hidden field for paging. This works in a default input...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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
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...
0
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
tracyyun
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...
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...

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.