473,698 Members | 2,643 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update Record in one Form and Open in another form?

thisisntwally
19 New Member
I've created a button in formA which updates the table in question, but i'd like to have an option to update and open the same record in form2

(different datafields are being entered so i don't think the
Expand|Select|Wrap|Line Numbers
  1. DoCmd.openForm "form2", , , "[field]=" & Me.[field]
approach will work).

Is there anyway i can use the .bookmark property to open the new form?

The primary key is autogenerated on update, but as they're not a part of the input(1) or update(2) forms I'd like to avoid using it if possible
Jun 29 '07
24 5062
thisisntwally
19 New Member
Ok. Its much more cleare now where the legs are growing from.
The problem is so far in record update. The syntax seems to be Ok. Just a silly question concerning this: is the form bound to [tbl Modifications]?
The next one: is form "Update" bound to [tbl Modifications]?
Both tables are indeed bound to [tbl Modifications]. There has been some who question my logic (i don't believe its all that ab-normal hehheh) but for user simplicity's sake im rather stubborn about having two forms. I do have a functioning tabbed form which combines the two, so I could get to work on some other functions in the database, but I hate the d@mn thing.
Jul 6 '07 #11
thisisntwally
19 New Member
Both tables are indeed bound to [tbl Modifications]. There has been some who question my logic (i don't believe its all that ab-normal hehheh) but for user simplicity's sake im rather stubborn about having two forms. I do have a functioning tabbed form which combines the two, so I could get to work on some other functions in the database, but I hate the d@mn thing.
speaking of, i went ahead and changed the control source for "txtkey" on the all-inclusive tabbed form to =DMAX("key",[tbl Modifications]) + 1, and now have the same problem. (as it used to be autonumber and there was no need to reference the key on the combined form, this was never an issue).

that being said, it seems to me as though there is a problem with my Dmax syntax...
Jul 6 '07 #12
thisisntwally
19 New Member
hoookay, Got some of this worked out, i just changed the update spec to Dmax and voila! (well at first i forgot to change the control source...and maybe there was something else...)

that being said, the second form still insists on updating the first record. It is of course friendly enough to change the key value to corrispond with the first form - thus creating duplicates and leading me to believe the problem is either still here:
Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2.     Dim stLinkCriteria As String
  3.  
  4.    stLinkCriteria = "[txtkey]= me.txtkey"
  5.     stDocName = "Update"
  6.     DoCmd.RunCommand acCmdSaveRecord
  7.     DoCmd.openForm stDocName, , , stLinkCriteria
  8.  
or perhaps on the second form here:
Expand|Select|Wrap|Line Numbers
  1. With CurrentDb.OpenRecordset("tbl modifications") '===>i deleted dbopentable - did nothing
  2.  
  3.         .Edit
  4.             !key = DMax("[key]", "[tbl Modifications]")
  5.           !UpdateDate = Date
  6.           !Mod = Me.txtMOD
  7.           !MRD = Me.txtMRD
  8.           !SLD = Me.txtSLD
  9.           !SCD = Me.txtSCD
  10.           !OSD = Me.txtOSD
  11.           !ObligationDocument = Me.objObligationDocument
  12.  
  13.         .Update
  14.         .Bookmark = .LastModified
  15.       End With
edit:i changed !key to = Me.txtkey, it then proceeded to update the same record, which oddly was no longer the first record but the second to last(the first of two 201's), gave it a null value, and moved it back to the top. The Implications of this are beyond my current comprehension (though they perhaps support hypothesis that the problem lies in the second form?)
Jul 6 '07 #13
FishVal
2,653 Recognized Expert Specialist
Both tables are indeed bound to [tbl Modifications]. There has been some who question my logic (i don't believe its all that ab-normal hehheh) but for user simplicity's sake im rather stubborn about having two forms. I do have a functioning tabbed form which combines the two, so I could get to work on some other functions in the database, but I hate the d@mn thing.
Really!?

Form RecordSource property is set to [tbl Modifications] and form fields ControlSource properties are set to [tbl Modifications] corresponding fields??!! Let me know whether is it really so.

If so why you update [tbl Modifications] programmaticall y. It will do nothing in "Update" form and cause record duplication in "Input" form, which in its turn will cause PK violation error on [tbl Modifications].key writing.
Jul 6 '07 #14
thisisntwally
19 New Member
*very embaressed
Really!?

Form RecordSource property is set to [tbl Modifications] and form fields ControlSource properties are set to [tbl Modifications] corresponding fields??!! Let me know whether is it really so.

If so why you update [tbl Modifications] programmaticall y. It will do nothing in "Update" form and cause record duplication in "Input" form, which in its turn will cause PK violation error on [tbl Modifications].key writing.
I don't(edit:do) think that the control source properties are set to fields in [tbl Modifications] (actually "txtkey" might be if what im doing in VB is setting control sources which as i type this begins to seem more likely)
Expand|Select|Wrap|Line Numbers
  1.  'in form1
  2. !key = DMax("[key]", "[tbl Modifications]") + 1
Expand|Select|Wrap|Line Numbers
  1. 'in form2
  2. !key = DMax("[key]", "[tbl Modifications]")
So in response to your 1st question: maybe?(edit:in response to your only question: yes)

Form1(imput) successfully adds a new record but as you said (well the inverse), Form2(update) duplicates the PK value. How can I get form2 to edit the record from Form1 without referencing the PK? Barring the sloppy thinking you've just pointed out I had been thinking my problem was in Form2 here:
Expand|Select|Wrap|Line Numbers
  1.  With CurrentDb.OpenRecordset("tbl Modifications", dbOpenTable)
edit:one last bit, in access form1(+2)>txtke y>Properties>co ntrol source = unbound, in case thats what you're asking about.
Jul 6 '07 #15
FishVal
2,653 Recognized Expert Specialist
*very embaressed


I don't(edit:do) think that the control source properties are set to fields in [tbl Modifications] (actually "txtkey" might be if what im doing in VB is setting control sources which as i type this begins to seem more likely)
Expand|Select|Wrap|Line Numbers
  1.  'in form1
  2. !key = DMax("[key]", "[tbl Modifications]") + 1
Expand|Select|Wrap|Line Numbers
  1. 'in form2
  2. !key = DMax("[key]", "[tbl Modifications]")
So in response to your 1st question: maybe?(edit:in response to your only question: yes)

Form1(imput) successfully adds a new record but as you said (well the inverse), Form2(update) duplicates the PK value. How can I get form2 to edit the record from Form1 without referencing the PK? Barring the sloppy thinking you've just pointed out I had been thinking my problem was in Form2 here:
Expand|Select|Wrap|Line Numbers
  1.  With CurrentDb.OpenRecordset("tbl Modifications", dbOpenTable)
I've meant form and form fields properties set when form was created or modified in Design view.
Open form (each form) in Design view and check whether form RecordSource property is set to [tbl Modifications] and form fields ControlSource properties are set to corresponding [tbl Modifications] fields.
If so record duplication actually occurs in "Input" form. When you start editing new record form automation creates new record, then your code do the same
Expand|Select|Wrap|Line Numbers
  1. With CurrentDB.OpenRecordset.....
  2.      .AddNew
  3.      .........
  4.      .Update
  5. End With
  6.  
P.S. I have to go now, will be back in 4-5 hours.
Jul 6 '07 #16
thisisntwally
19 New Member
I've meant form and form fields properties set when form was created or modified in Design view.
Open form (each form) in Design view and check whether form RecordSource property is set to [tbl Modifications] and form fields ControlSource properties are set to corresponding [tbl Modifications] fields.
ok those are definately unbound. im pretty sure that the problem is that my editrecordButto n on Form2 is copied pretty directly from the original addrecordButton on Form1 - i just changed .addnew to .edit
Expand|Select|Wrap|Line Numbers
  1. Private Private Sub comRecord_Click()
  2. Dim temp       As Variant
  3. On Error GoTo Err_comRecord_Click
  4.  
  5.     temp = SysCmd(acSysCmdSetStatus, "Filling table...")
  6.  
  7. With CurrentDb.OpenRecordset("tbl Modifications", dbOpenTable)
  8.         .Edit
  9.           !key = DMax("[key]", "[tbl Modifications]")
  10.           !UpdateDate = Date
  11.           !Mod = Me.txtMOD
  12.           !MRD = Me.txtMRD
  13.           !SLD = Me.txtSLD
  14.           !SCD = Me.txtSCD
  15.           !OSD = Me.txtOSD
  16.           !ObligationDocument = Me.objObligationDocument
  17.  
  18.         .Update
  19.         .Bookmark = .LastModified
  20.       End With
  21.  
  22. temp = SysCmd(acSysCmdClearStatus)
  23.  
  24. Exit_comRecord_Click:
  25.     Exit Sub
  26.  
  27. Err_comRecord_Click:
  28.     MsgBox Err.Description
  29.     Resume Exit_comRecord_Click
  30.  
  31. End Sub
Im going to look into this recordset business...
Jul 6 '07 #17
FishVal
2,653 Recognized Expert Specialist
ok those are definately unbound. im pretty sure that the problem is that my editrecordButto n on Form2 is copied pretty directly from the original addrecordButton on Form1 - i just changed .addnew to .edit
Expand|Select|Wrap|Line Numbers
  1. Private Private Sub comRecord_Click()
  2. Dim temp As Variant
  3. On Error GoTo Err_comRecord_Click
  4.  
  5. temp = SysCmd(acSysCmdSetStatus, "Filling table...")
  6.  
  7. With CurrentDb.OpenRecordset("tbl Modifications", dbOpenTable)
  8. .Edit
  9. !key = DMax("[key]", "[tbl Modifications]")
  10. !UpdateDate = Date
  11. !Mod = Me.txtMOD
  12. !MRD = Me.txtMRD
  13. !SLD = Me.txtSLD
  14. !SCD = Me.txtSCD
  15. !OSD = Me.txtOSD
  16. !ObligationDocument = Me.objObligationDocument
  17.  
  18. .Update
  19. .Bookmark = .LastModified
  20. End With
  21.  
  22. temp = SysCmd(acSysCmdClearStatus)
  23.  
  24. Exit_comRecord_Click:
  25. Exit Sub
  26.  
  27. Err_comRecord_Click:
  28. MsgBox Err.Description
  29. Resume Exit_comRecord_Click
  30.  
  31. End Sub
Im going to look into this recordset business...
Code for record updating and, I'm pretty sure, there is also code for fields populating. Usually its better to let Access do it via bound form automation.
Why not to bind Form2 (maybe Form1 too, but Form2 definitely should be bound) to [tbl Modifications] and let Access do this behind the scenes?

BTW DoCmd.OpenForm with WhereCondition argument is indeed useless on unbound form.
Jul 7 '07 #18
thisisntwally
19 New Member
Code for record updating and, I'm pretty sure, there is also code for fields populating. Usually its better to let Access do it via bound form automation.
Why not to bind Form2 (maybe Form1 too, but Form2 definitely should be bound) to [tbl Modifications] and let Access do this behind the scenes?

BTW DoCmd.OpenForm with WhereCondition argument is indeed useless on unbound form.
I just found a seldom used 'ammendment number' that will soon become manditory now that i can identify the records without the autonumber/dmax (procurement request + amendment number => PR + Mod # =yay!). I'm hoping with that it will be easier to reopen a record in a new form now that i wont be referencing calculated fields.... now if i could only find those postings on linking with multiple criteria....I'l l be back just as soon as im in deep water again.

ps: SQL czars, gurus, etc beware - if things go well you're next
Jul 9 '07 #19
thisisntwally
19 New Member
Ok so form two was indeed unbound, a problem which has been addressed.

this didnt work:
Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2.     Dim stLinkCriteria As String
  3.  
  4.     stDocName = "Update"
  5.  
  6.     stLinkCriteria = "[txtkey]=" & Me!txtkey
  7.     DoCmd.openForm stDocName, , , stLinkCriteria
which leads to "syntax error (missing operator) in query expression '[txtkey]='

so i tried this approach:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.openForm "Update"
  2.  
  3. Forms!Update!txtkey.SetFocus
  4.  
  5. DoCmd.FindRecord Forms![Input Form]!txtkey
which gives me "An expression you entered is the wrong data type for one of the arguements" (goes to error on last line)

any ideas?
Jul 10 '07 #20

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

Similar topics

0
2776
by: Sue Adams | last post by:
I actually have two issues/questions: I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db. The code I use to get it from the db table is: ''Retrieve the Registration Identification Number strRegisterID = Rs("Register_ID") Prior to testing my code and actually updating the db, I''m trying to write it to the page to make sure their isn''t a loop or massive...
9
4351
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user for any changes of ratings on that day. The resulting data table grows by approx 600 records per...
4
2146
by: Jonathan Upright | last post by:
Greetings to anyone who can help: I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable DataGrid" at the project selector screen. As you may know, it defaults to the Microsoft SQL database "pubs". I've followed the instructions in the comments and also changed everything pertaining to SQL over to OLEDB. (i.e. Changed SqlDbType. to OleDbType.) I also changed the datafield names and variable names accordingly. The page...
1
2020
by: mursyidatun ismail | last post by:
Dear all, database use: Ms Access. platform: .Net i'm trying to update a record/records in a table called t_doctors by clicking da edit link provided in the database. when i ran through da browsers and click update it gave me this error: Specified argument was out of the range of valid values. Parameter name:
1
8500
by: Mark Reed | last post by:
Hi All, I'm having a problem with the following code. I've read quite a lot of old posts regarding the issue but none seem to affer a solution. The scenario is. I have a bound form which contains a couple of memo fields. I need to keep some sort of log as to when each update of the memo field occurs so I have locked bot the memo fields on the main form. To edit them, the user double clicks the ememo field which then opens an unbound...
5
2595
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
9
3332
by: mtgrizzly52 | last post by:
Hi all, I've looked for an answer for this in lots of books, online in several discussion groups and have not found the answer which I feel may be very simple. What I want to do is have a switchboard with several active buttons on it for entering new data, updating data, reports etc. The new data and report stuff is easy, but the update button has me baffled. What I want to have happen is when the update button is clicked, a parameter...
0
3236
by: Access Programming only with macros, no code | last post by:
ERROR MESSAGE: Could not update; currently locked by another session on this machine. BACKGROUND I have the following objects: Table1 - HO (which has about 51,000+ records) Table2 - Contact (which has 68,000+ records)
1
2458
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Order Record</title> <meta name="Microsoft Border" content="tlb, default"> </head>
2
2634
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to update the information which is stored in a SQL database. In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
0
8611
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,...
0
9031
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 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...
1
8904
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,...
0
8876
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 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...
0
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
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...
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
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...

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.