I want to have an "Edit" form=fEditLoc for rows in a subform=subfSho wLoc. Once the form opens, I want to be able to create a new record in the table=tLoc which I will then edit.
Or to put it another way, I want to edit a record, and then do a "Save As" to a new record. Seems simple, but I can't keep the data in all the fields when I move the form to the NewRecord position. So how do I do this?
16 3178 ADezii 8,834
Recognized Expert Expert @OldBirdman
Hello OldBirdman, try this out and see what happens: - 'Select Current Record
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
-
-
'Copy Current Record
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
-
-
'Paste Append Record
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70
Thank you. These tools will work for this.
Just curious, but I think somewhere I read that DoMenuItem was to be avoided if possible. The relative position of the items may change, or something. Is this something I should be concerned about?
I think I replied too quickly. I would like my "Save As" to leave the original record unchanged, as happens if we edit a file in say NotePad, make some changes, and decide to create a new file. We SaveAs and continure editing. At the end, the original file is unchanged, and the new file has the changes from before the SaveAs and after it (presuming a final Save before closing).
Line #2 of the code suggested in Post #2 saves the record. If I select before any changes are made, it is un-selected when form becomes dirty.
I could save all the fields using each control's OldValue property. Then I select the record, allowing Access to save the changed record. On FormClose, I would have to move back to the original record, and restore the original values and save it. Procedures would have to be recursive, because I might want to create a series of records, each a slight change from the previous one.
1. Call form
2. Make changes, say txtField = Test 1
3. "Save As" to create a new record
4 Change the 1 to a 2, avoiding typing the word "Test" and any other common data fields
5. "Save As" to create a new record
6. ... Repeat as necessary
This seems clumsy, crude, and amaturish. Like most of my code, I'm afraid.
ADezii 8,834
Recognized Expert Expert @OldBirdman
I do have a solution that I based on the [FirstName] and [LastName] Fields of the Employees Form in the Northwind Sample Database. Make changes to the First and Last Name Fields, then execute the following code within the context of the Form, making sure to previously Declare the Globals. An exact Duplicate of the Record will be created then Appended. The Original Record will revert back to its Original State prior to the changes. I know it is a little convoluted, but for now, see if it will do until a better solution comes along. I tested it and it actually does work! (LOL)! - Dim strSQL As String
-
-
'*******************************************************************************************
-
'Store Original Values in Public Variables Declared in a Standard Code Module
-
glngEmployeeID = Me![EmployeeID]
-
gstrFirstName = Me![FirstName].OldValue
-
gstrLastName = Me![LastName].OldValue
-
'*******************************************************************************************
-
-
'*******************************************************************************************
-
'Define the SQL Statement that will restore the Original Values to the very Record from which
-
'changes were made, and a Duplicate created
-
strSQL = "UPDATE Employees SET Employees.FirstName = '" & gstrFirstName & "', " & _
-
"Employees.LastName = '" & gstrLastName & "' Where Employees.[EmployeeID] = " & _
-
glngEmployeeID
-
'*******************************************************************************************
-
-
'*******************************************************************************************
-
'Duplicate the Record with modifications
-
'Select Current Record
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
-
-
'Copy Current Record
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
-
-
'Paste Append Record
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70
-
'*******************************************************************************************
-
-
'*******************************************************************************************
-
'Restore Original Values to the Original Record
-
CurrentDb.Execute strSQL, dbFailOnError
-
'*******************************************************************************************
-
-
'P.S. - At some point you 'MUST' Reset the Public Variables before duplicating this Procedure
OK, Good. I never used an UPDATE query pefore, so that was my missing piece. I don't get the Global Variables. Why? strSQL = "UPDATE ..." & Me![EmployeeID].OldValue & "..." & Me![FirstName].OldValue & ..... saves the data locally. It only has to last from line 13 to line 32.
Thank you for your time & effort.
ADezii 8,834
Recognized Expert Expert @OldBirdman
Anytime, sorry for the confusion, strSQL can be Declared Locally as is.
This doesn't work, and I'm going nuts trying to figure why.
I have 2 tables, linked in Relationships. I'm trying to create a simple form to edit 2 of the fields in the child table, and be able to start an edit and then do a "Save As". - Tables
-
Table 1 Name = tPhotographers
-
Key as Autonum (Random) = PK
-
...
-
-
Table 2 Name = tPhotographerLocations
-
Key as Autonum (Random) = PK
-
Photographers as Long 'Points to Key in table = tPhotographers
-
LastDate as Date
-
Type as String
-
Location as String
The form has 5 textboxes for the 5 fields in the table, named txtXXX where XXX is the name in the table. For testing, this form is being opened from the DataBase (Forms) window, and no other forms are open. - Private Sub Form_Load()
-
'Photographers key = 782320442
-
Me.RecordSource = "SELECT * FROM tPhotographerLocation WHERE Key=1251495069"
-
End Sub 'Form_Load
-
I have 1 record (Key=1251495069 ) a test record with Photographers pointing to a test record. Everything displays correctly at this point.
In txtLocation, I change the current value "Test 1" to my new value "Test 2". I press button = cmdSaveAs to create a new record, and to restore the initial record to its original state ("Test 1"). - Private Sub cmdSaveAs_Click()
-
Dim strSQL As String
-
Dim iiHoldPtr As Long
-
-
iiHoldPtr = txtPhotographer
-
If Me.Dirty Then
-
'Build SQL to restore original record
-
strSQL = "UPDATE tPhotographerLocation " & _
-
"SET Type='" & Nz(txtType.OldValue, txtType) & _
-
"', Location='" & Nz(txtLocation.OldValue, txtLocation) & _
-
"' WHERE Key=" & txtKey
-
Else
-
strSQL = ""
-
End If
-
-
'Select the record now being edited
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
-
'Copy the Record
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
-
'Paste append record to create new record
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
-
Me.Dirty = False 'Force Save for test purposes only
-
txtPhotographer = iiHoldPtr
-
Me.Dirty = False 'Force Save for test purposes only
-
'Restore original record (if necessary)
-
If strSQL <> "" Then CurrentDb.Execute strSQL, dbFailOnError
-
End Sub
With a breakpoint at Line 22, I have the following in Immediate (window). First, I did a cntl+V to paste the clipboard into Immediate. - txtKey txtPhotographer txtLastDate txtType txtLocation
-
1251495069 782320442 4/8/2009 X Test 2
I then printed some controls and variables: - ?txtKey, txtPhotographer, txtLastDate, txtType, txtLocation
-
1976622305 0 Null X Test 2
-
-
?me.Dirty
-
True
Note that the foreign key txtPhotographer is 0 and invalid as there is no key=0 in table=tPhotogra phers. The date field is Null, also invalid, but the other fields are correct.
Attempting to run Line 22 gets me - Run-time error '3201': You cannot add or change a record because a related record is required in table 'tPhotographers'.
which is because txtPhotographer is now 0 and invalid. If I skip Line 22, and run Line 23, Line 24 also works. I really don't want to do this, because now UnDo in not possible, but for now, OK.
Line 26 restores the original record, and closing the form leaves me with 2 records, but the date is null in the 2nd record.
If I now change txtLocation to "Test 3" and continue, more problems occur. So I need to understand why this part doesn't work, rather than just force it with more code like Line 23.
A real-life example would be if a photographer visits a city briefly, the location might be entered as txtLocation = - AnyCity, SomeState, Country
If he returns for a more extensive visit, he might want to edit this, adding local locations such as - Central Park, AnyCity, SomeState, Country
-
Waterfront Park, AnyCity, SomeState, Country
-
Courthouse Park, AnyCity, SomeState, Country
-
Civic Center, AnyCity, SomeState, Country
-
...
-
Line 21 is the code that is producing incorrect results. Something is very wrong with this approach. Giving up the office clipboard is an undesired side-effect of this method, but I could live with it if it is the only way. Can it be fixed?
It seems like the code might be: - rst = tPhotographerLocations
-
rstclone = tPhotographerLocations.clone
-
rstclone = set to current record
-
rst = set to new record
-
assign rst from rstclone
-
rstclone.undo
Any ideas here?
ADezii 8,834
Recognized Expert Expert @OldBirdman
Can you send me a Copy of the Database if I give you my E-Mail Address in a Private Message?
That presented was a tiny piece of a larger system, including linked tables. I'll see if I can isolate this into a test database, as the problem is fairly simple.
When I've sent my problems to others, they don't recreate on their machines. That implies that mine are corrupt, although I run two different versions of Office (2000 and 2002). Both machines, 2 versions of a program produce the same symptoms.
I am going to try to figure how to do this with direct manipulation of the tables, as I hinted at the end of my previous post.
Thank you for your effort and concern.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Phil Powell |
last post by:
create table if not exists nnet_produkt_varegruppe (
nnet_produkt_varegruppe_id int not null auto_increment,
primary key(nnet_produkt_varegruppe_id),
nnet_produkt_varegruppe_navn varchar(255) not null
);
create table if not exists nnet_produkt_farge (
nnet_produkt_farge_id int not null auto_increment,
primary key(nnet_produkt_farge_id),
|
by: dev |
last post by:
how create a temp table as a copy of a existing table and then update1 field
and insert the hole temp table back in the existing table?
please any help?
if i have 10 fields in 1 record and about 100 records and a field.status=1
in a existing_table and
i want to create a temp_table with all the recordse and values of the
existing_table and then update the field.status to 2 and insert in 1 query
the temp_table in the existing_table
|
by: Michael Jackson |
last post by:
I have a stored procedure to create a table. In my program I want the user
to name the table to be created, therefore I pass a parameter to the SP for
the table name. I cannot get it to work.
It creates a table called "@NewTableName".
Any ideas?
CREATE PROCEDURE dbo.sp_FFProduction_CreateTable
(
|
by: Wolfgang Kreuzer |
last post by:
Hello all,
I have two tables - Projects and ProjectStruct
Table Projects contains master records of the projects, ProjectStruct
allows to define a project herarchie and contains the fields
PrjStructId, ProjectId, PrjStructName, ..., ParentId
PrjStructParent contains a reference to the parent or to itselves if
record is top-level-record for a project.
|
by: poohnie08 |
last post by:
i have a excel spreadsheet showing staff name, date,work hour, ot
hour, slot1, slot2, slot3, slot4 and others). The "()" will keep
repeating from day 1 until end of month.
eg in excel spreadsheet,
==============================================================================
A1 |A2 A3 A4 A5 A6 A7 A8 |A9
A10 A11
| 01/02/04 |02/02/04
StaffName |Work Hr OT Hr Slot1...
| |
by: flkeyman |
last post by:
Work in legal office. Trying to create solid designed database
structure. This is list of tables w/fields and primary keys. Any
comments/advice greatly appreciated.
tbl-Defendants
CaseNumber (primary key)
FirstName
MiddleName
LastName
|
by: Peter Nurse |
last post by:
For reasons that are not relevant (though I explain them below *), I
want, for all my users whatever privelige level, an SP which creates
and inserts into a temporary table and then another SP which reads and
drops the same temporary table.
My users are not able to create dbo tables (eg dbo.tblTest), but are
permitted to create tables under their own user (eg MyUser.tblTest). I
have found that I can achieve my aim by using code like...
|
by: max |
last post by:
Hello,
I am a newbye, and I'm trying to write a simple application.
I have five tables with three columns; all tables are identical; I need to
change some data in the first table and let VB updates the same data in all
other four tables in the right places.
I know it would be possible by using the ForeignKeyConstraint object. I have
created the tables using the DataSet Visual Tool and I know it doesn't
create any ForeignKeyConstraint obj....
|
by: etuncer |
last post by:
Hello All,
I have Access 2003, and am trying to build a database for my small
company. I want to be able to create a word document based on the data
entered through a form. the real question is this: can Access create
the document and place it as an OLE object to the relevant table?
Any help is greatly appreciated.
Ricky
|
by: lakuma |
last post by:
Hi,
I have a table called A (say) with columns called name, place, animal and thing.
I would want to write an on insert trigger on this table, which would create a table with the name of the value entered in the name column.
Let's say a new column is entered with the value of name column as mickey. I want to create a table called mickey, with the help of triggers.
I'm really new to this and i would like some help. Thanks in advance for...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |