473,386 Members | 1,817 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,386 software developers and data experts.

How to stop a field from populating when duplicating a record in an Access form?

4
I have an Access form with action buttons one of which is a duplicate record button. When activated, the duplicated record has one of the yes/no fields toggled on. It is not toggled on in the originating record; just the duplicated record. Any idea of why it is happening and how to correct or stop it? Any help will be greatly appreciated. Thank you.
Jun 19 '19 #1

✓ answered by zmbd

as Neopa suggested... my thoughts on places to check.

Access does not "randomly" set values in records - upon creation of the record all field values are null unless and/or until something takes an action such as a default value.

So in order of thought:
Tables at design, the [Yes/No] fields have a default value of "No" (=== false) when initially added to the table. The most common habit is for people to change this value to "Yes" or delete the value... creating a null... which can have some really fun consequences for searches and if one pushes the record to a SQL-Server

Event in the form:
Despite the fact that the control button is running via macro vs vba... either the form's or the control's after_update event will still trigger once the record is pasted. Do we have any VBA or macro code at the form level that could potentially alter the value of the field.

Event at the table level:
I would dare say, that not many people know that this can be done in the newer versions of Access - the equivalent of a trigger for other databases. A macro can be created that either takes direct action itself or can call a VBA function. You would most likely know if you've done this, hence, why it's the last place I would look for such a Gremlin.

---
I've built a test database in an attempt to duplicate your experience; however, I am not able to do so with what I have done.

Please do me a favor,
Open the command button properties and show the macro editor.
select one row of the macro code, doesn't matter which, we just want the focus within the script.
Press <Ctrl><A> to select all
Press <Ctrl><C> to copy all

Come back to this thread
Click in the reply box and <Ctrl><P>
Select the pasted text and click on the [CODE/] format
You should get something like this (of course yours will have other commands ;-) ):
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-16" standalone="no"?>
  2. <UserInterfaceMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application"><UserInterfaceMacro For="Command2" Event="OnClick"><Statements><Action Name="FindNextRecord"/></Statements></UserInterfaceMacro></UserInterfaceMacros>
don't worry about stepping the code one of us will take care of that when we review it.

What I am looking for is anything extra that the macro may be executing behind the scenes and this is the most sure way to check that there isn't an extra call being made.

---
On a side note:
Something I find a bit interesting is that you are making a duplicate record which tells me that you do not have a primary key set for this table... why are we duplicating record information? This then suggests that the database may not be normalized in that we're repeating the same information... there are certainly very valid reasons, say an event in a calendar or reoccurring sale of an inventory item to a customer (I could think of other ways and means to record this event).

10 1497
NeoPa
32,556 Expert Mod 16PB
What is it that you do when that button is triggered? What code or macros are executed?

It doesn't make a great deal of sense to ask what you're doing wrong without ever telling us what you're doing.
Jun 19 '19 #2
zmbd
5,501 Expert Mod 4TB
Is the control bound to the [Yes/No] data field?
Jun 19 '19 #3
twinnyfo
3,653 Expert Mod 2GB
KaeKae,

I'm with NeoPa on this one. Data doesn't just randomly change in MS Access. You have to tell it to do something. Listing the code you are using would be extremely helpful if you want us to hepp.
Jun 19 '19 #4
KaeKae
4
So sorry Neopa. I used the button wizard to create the duplicate record button and it created the following (I added the save record step at the end):

Expand|Select|Wrap|Line Numbers
  1. OnError (Next,)
  2. SelectRecord
  3. If [MacroError]=0 Then
  4.    Copy
  5. End If
  6. If [MacroError]=0 Then
  7.    RecordsGoToNew
  8. End If
  9. If [MacroError]=0 Then
  10.    SelectRecord
  11. End If
  12. If [MacroError]=0 Then
  13.    Paste
  14. End If
  15. If [MacroError]=0 Then
  16.    MessageBox (=[MacroError].[Description], Yes, None, )
  17. End If
  18. SaveRecord
Hope that provides the information you were looking for in order to assist. I understand that Access would not perform a random action but I have no macros that have anything to do with the Cancel field that gets toggled on. I do have it in some queries but none of them are tied to the form; just reports. Thank you.
Jun 19 '19 #5
zmbd
5,501 Expert Mod 4TB
Nothing in that macro should change the underlying record, while woefully convoluted, it's really nothing more than a [Ctrl][C]/[Ctrl][V]

Have you checked if ...
1) Default value of the field is in the true state.
2) Form level event that is running code that toggles the field value
3) Table level event that is running code that toggles the field value
Jun 19 '19 #6
KaeKae
4
Yes, zmbd, it is a true copy/paste function but it the database is for an inexperienced user so the button is a helpful tool. Again, it is why I am confused why Access is choosing a random field to change to the true state. I guess I'm too much of an amateur but I don't understand your 1, 2, 3. Is it your solution to correct the problem?
Jun 19 '19 #7
NeoPa
32,556 Expert Mod 16PB
I suspect that Zmbd is suggesting that you look in those three places to find where a DefaultValue for that Control on your form is being set.

It seems likely that one of those has a default set such that any new records that are added, without that value being explicitly set, will be added with the default.

BTW Thank you for your earlier response. It's so much easier when people respond to your suggestions simply and easily.
Jun 20 '19 #8
zmbd
5,501 Expert Mod 4TB
as Neopa suggested... my thoughts on places to check.

Access does not "randomly" set values in records - upon creation of the record all field values are null unless and/or until something takes an action such as a default value.

So in order of thought:
Tables at design, the [Yes/No] fields have a default value of "No" (=== false) when initially added to the table. The most common habit is for people to change this value to "Yes" or delete the value... creating a null... which can have some really fun consequences for searches and if one pushes the record to a SQL-Server

Event in the form:
Despite the fact that the control button is running via macro vs vba... either the form's or the control's after_update event will still trigger once the record is pasted. Do we have any VBA or macro code at the form level that could potentially alter the value of the field.

Event at the table level:
I would dare say, that not many people know that this can be done in the newer versions of Access - the equivalent of a trigger for other databases. A macro can be created that either takes direct action itself or can call a VBA function. You would most likely know if you've done this, hence, why it's the last place I would look for such a Gremlin.

---
I've built a test database in an attempt to duplicate your experience; however, I am not able to do so with what I have done.

Please do me a favor,
Open the command button properties and show the macro editor.
select one row of the macro code, doesn't matter which, we just want the focus within the script.
Press <Ctrl><A> to select all
Press <Ctrl><C> to copy all

Come back to this thread
Click in the reply box and <Ctrl><P>
Select the pasted text and click on the [CODE/] format
You should get something like this (of course yours will have other commands ;-) ):
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-16" standalone="no"?>
  2. <UserInterfaceMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application"><UserInterfaceMacro For="Command2" Event="OnClick"><Statements><Action Name="FindNextRecord"/></Statements></UserInterfaceMacro></UserInterfaceMacros>
don't worry about stepping the code one of us will take care of that when we review it.

What I am looking for is anything extra that the macro may be executing behind the scenes and this is the most sure way to check that there isn't an extra call being made.

---
On a side note:
Something I find a bit interesting is that you are making a duplicate record which tells me that you do not have a primary key set for this table... why are we duplicating record information? This then suggests that the database may not be normalized in that we're repeating the same information... there are certainly very valid reasons, say an event in a calendar or reoccurring sale of an inventory item to a customer (I could think of other ways and means to record this event).
Jun 20 '19 #9
KaeKae
4
zmbd you are a genius and I am an idiot! I have and after_update on a related field in the form (Cancel_Date) to make true if a data is entered in it. Would you recommend On_Change as a better option?


And you are right; the database is not normal. Based on the data source, the user's level of comfort and other factors, it is not designed by normal standards. Not something I would prefer but based on the circumstances of the client, it meets the needs and expectations and they are happy with it. I am just making some requested changes and I haven't been in it for over a year. A bit rusty apparently.
Jun 21 '19 #10
zmbd
5,501 Expert Mod 4TB
::blush::
Anyone that steps on their toes enough learns not to step on their toes - Lord knows, I've stepped on my toes a few times - I advise steel toes! :)

The On_Change event might work; however, we don't have a good understanding your your design. I say give it a try - make a copy of your database, change the code to the On_Change event. Worse case is that it doesn't work...

If it doesn't work then we should understand what the macro in the related field is doing and why.

My other thought is to use the Me.NewRecord property of the form; however, using macros, I don't think there is a direct way to check if you are on a new record. You might be able to hybridize the Macro to execute vba to check; however, IMHO, you should just move to pure vba at that point.

> Design, sometimes the client doesn't really understand what they want... if you show them a better way they may take to it like a duck to water.
Jun 22 '19 #11

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

Similar topics

1
by: Colin Graham | last post by:
I am writing this piece of code to show the previous record on a control on the form but i keep getting the error message "Error 3021 no current record " and the line marked *** gets highlighted. I...
2
by: Danny | last post by:
I am creatng a form and using wizard to automate some things. I want the user to be able to Duplicate a record so I set this up behind a command button on the form. THe wizard did all the work. ...
4
by: steph | last post by:
Hello, I've got a text field in an access form (Microsoft Access 2002, SP3), that the user has to fill out. Now I don't want the user to leave this field (and this record) until he has filled...
6
by: MLH | last post by:
When the vehicle entry form (frmVehicleEntryForm) first opens, the additional owner SubForm control (frmAddnlOwnrListSubForm) is enabled. You can click on it and it will accept the focus. But after...
6
by: jpatchak | last post by:
Hello All, I am trying to code a command button on a form to create a duplicate record and renumber it. The code I have in the command button currently is; DoCmd.DoMenuItem acFormBar,...
2
by: Kanashii | last post by:
First off - I want to thank all who respond / try to help out and even those who took a moment to read over my question. Please be patient as I am -very- new to VB in general and unfortunately...
2
by: Tom Clavel | last post by:
Scratching my head. I am using the filter property on a combo box .AfterUpdate event to get to a single client record. This is causing a some strange behavior: As I enter a subform, I get a no...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
4
by: Susan Bricker | last post by:
I have a form that displays record information in Continuous Record display (scrollable list). One of the fields in the record is an Integer value called "rcode" (reason code). But, I don't want...
2
by: cambar | last post by:
When Access db is first opened and the first record is entered, tabbing on subform works properly. However, when subsequent records are entered, the subform retains memory of the last field filled in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...

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.