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

How to force a "new record write"

sueb
379 256MB
I have a form with a subform, and this subform allows the addition of a new child record using only a few essential fields. Typically, after entering these few fields, the user goes on to fill in the rest of the fields, and that action happens by clicking on a button that opens a separate form that displays all the fields for the new child record.

The problem is that it doesn't. It displays the separate form, but on a blank record rather than the newly added record. If the user moves the cursor in the abbreviated form into a field for a different child record, and THEN clicks on the button, the separate form displays the newly added record.

How can I force the child record to be written (probably, in the code for the "separate form" button)?
Dec 28 '10 #1

✓ answered by ADezii

Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2. Dim stMainForm As String
  3. Dim stLinkCriteria As String
  4.  
  5. stDocName = "IURs: subform"
  6.  
  7. '****************** The following Line will NOT Save theRecord ******************
  8. 'Forms![Patient_IUR_Overview]![IURs Abbreviated: subform].Form.Dirty = False
  9. '********************************************************************************
  10.  
  11. '******************* The following Lines WILL Save the Record *******************
  12. 'If Me.Dirty Then Me.Dirty = False
  13. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  14. '********************************************************************************
  15.  
  16. stLinkCriteria = "[IURs.IUR Index]=" & Me![IUR Index]
  17.  
  18. DoCmd.OpenForm stDocName, , , stLinkCriteria

20 3481
ADezii
8,834 Expert 8TB
You can force the Save of a Record in a Sub-Form by setting the Dirty Property of the Sub-Form Object itself to False. This, of course, will not stop Error Messages if Validation Rules, Input Masks, Required Property of any Control on the Sub-Form is violated prior to the Save. Substitute your Main Form and Sub-Form Names below in the following Code:
Expand|Select|Wrap|Line Numbers
  1. Forms![<Main Form>]![<Sub-Form>].Form.Dirty = False
Dec 28 '10 #2
sueb
379 256MB
I don't know what it is about this application's syntax that stumps me so, but I simply could not get this line to do anything other than give an error. Here is the whole module that's attached to the "go to the separate form" button:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Open_IUR_Subform_Click()
  2. On Error GoTo Err_Open_IUR_Subform_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stMainForm As String
  6.     Dim stLinkCriteria As String
  7.  
  8.     stMainForm = "Patient_IUR_Overview"
  9.     stSubForm = "IURs Abbreviated: subform"
  10.     stDocName = "IURs: subform"
  11.  
  12.     'Forms![<stMainForm>]![<stSubForm>].Form.Dirty = False
  13.     'Forms![stMainForm]![stSubForm].Form.Dirty = False
  14.     'Forms![<stSubForm>]![<stDocName>].Form.Dirty = False
  15.     'Forms![stSubForm]![stDocName].Form.Dirty = False
  16.  
  17.     stLinkCriteria = "[IURs.IUR Index]=" & Me![IUR Index]
  18.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  19.  
  20. Exit_Open_IUR_Subform_Click:
  21.     Exit Sub
  22.  
  23. Err_Open_IUR_Subform_Click:
  24.     MsgBox Err.Description
  25.     Resume Exit_Open_IUR_Subform_Click
  26.  
  27. End Sub
  28.  
The "OpenForm" thing works great; I just included it in the interest of completeness.
Jan 6 '11 #3
ADezii
8,834 Expert 8TB
Use the Syntax that I showed you in Post# 2, namely:
Expand|Select|Wrap|Line Numbers
  1. Forms![Patient_IUR_Overview]![IURs Abbreviated: subform].Form.Dirty = False
Jan 6 '11 #4
sueb
379 256MB
Whether I use constants in that line, or whether I use the actual form names, I get the following error:

"Pre-Admitting IURs can't find the form 'Patient_IUR_Overview' referred to in a macro expression or Visual Basic code."
Jan 6 '11 #5
ADezii
8,834 Expert 8TB
Where is Pre-Admitting IURs originating from?
Jan 6 '11 #6
sueb
379 256MB
That's the name of the database itself. I forget where that's set.
Jan 6 '11 #7
sueb
379 256MB
Anyone else have any ideas to help me with this?
Jan 11 '11 #8
ADezii
8,834 Expert 8TB
The only thing that I can tell you, sueb, is that the Syntax below does work. I happen to have a copy of the DB that you sent me, and tested it again. The only thing that I can think of is that [Patient_IUR_Overview] is not Open when the Code is being executed. If the Back End has not changed, you can Upload the Front End and I'll take a look at it again.
Expand|Select|Wrap|Line Numbers
  1. Forms![Patient_IUR_Overview]![IURs Abbreviated: subform].Form.Dirty = False
Jan 11 '11 #9
sueb
379 256MB
Oh, thanks, Adezii! Here's the front end.
Attached Files
File Type: zip IURs.zip (472.3 KB, 118 views)
Jan 11 '11 #10
ADezii
8,834 Expert 8TB
Have a Look/See:
Attached Files
File Type: zip IURs_2.zip (214.8 KB, 91 views)
Jan 11 '11 #11
sueb
379 256MB
Gosh, I don't know, Adezii. I still get that same error. Even though the line you sent me was exactly the same as one I had tried before, I copied and pasted it out of your version, just to make sure, but to no avail.

This is really weird. Is there some "Access-level" setting that could be involved? I can't imagine what that would be, but this just isn't working in my copy.
Jan 11 '11 #12
ADezii
8,834 Expert 8TB
This is really weird. If you can, send me now the Copy that isn't working even though the Code chaqnges work on my end. Nothing has changed in the Back End, correct?
Jan 11 '11 #13
sueb
379 256MB
Okay, here's both the front end and a safe back end. I surely appreciate your help with this!
Attached Files
File Type: zip IURs.zip (462.8 KB, 75 views)
File Type: zip IURSTATUS_BE.zip (90.2 KB, 89 views)
Jan 11 '11 #14
ADezii
8,834 Expert 8TB
Give this a try, sueb.
Attached Files
File Type: zip IURs_3.zip (211.9 KB, 84 views)
Jan 12 '11 #15
sueb
379 256MB
That seems to have done the trick! I see that the code is not at all the same:

didn't work:

Expand|Select|Wrap|Line Numbers
  1. Forms![Patient_IUR_Overview]![IURs Abbreviated: subform].Form.Dirty = False
did work:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
and I'd love to understand what's going on. Is there something about my database that was different than you first expected? (And that maybe I should change?) Or what?
Jan 12 '11 #16
ADezii
8,834 Expert 8TB
I'll be perfectly honest and tell you that I am not exactly sure what is going on since it was working perfectly with an older Back End. In any event, I took an alternative approach. Since the Code is being executed within the context of the Sub-Form, an explicitly Save should do the trick in Saving the Current Record there, and Opening the other Form. This will simply have to go down as an Unsolved Mystery until I can find the time to investigate further! (LOL).
Jan 12 '11 #17
sueb
379 256MB
Well, thanks, again, ADezii. It's working smoothly. If you ever do get a bead on this, I'll be very interested to hear it.
Jan 12 '11 #18
ADezii
8,834 Expert 8TB
You bet, sueb.
Jan 12 '11 #19
sueb
379 256MB
Adezii, would you consider editing your post where you sent me the version that worked to include the line that works? You know, just for the sake of those who come after...
Jan 12 '11 #20
ADezii
8,834 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2. Dim stMainForm As String
  3. Dim stLinkCriteria As String
  4.  
  5. stDocName = "IURs: subform"
  6.  
  7. '****************** The following Line will NOT Save theRecord ******************
  8. 'Forms![Patient_IUR_Overview]![IURs Abbreviated: subform].Form.Dirty = False
  9. '********************************************************************************
  10.  
  11. '******************* The following Lines WILL Save the Record *******************
  12. 'If Me.Dirty Then Me.Dirty = False
  13. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  14. '********************************************************************************
  15.  
  16. stLinkCriteria = "[IURs.IUR Index]=" & Me![IUR Index]
  17.  
  18. DoCmd.OpenForm stDocName, , , stLinkCriteria
Jan 12 '11 #21

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

Similar topics

2
by: ZubZero | last post by:
Hello, i have to write a utility in c++ for windows 2k/XP. But i have 2 difficult problems. I asked many programmers i know, but none of them was able to tell me how i can do this. 1. I...
0
by: elvin | last post by:
Okay - apologize in advance for the length, but I want to make sure all you knowledgeable and helpful people have all the details you need to hopefully point my newbie rear in the right direction....
12
by: Olaf Baeyens | last post by:
I am porting some of my buffer class code for C++ to C#. This C++ class allocates a block of memory using m_pBuffer=new BYTE; But since the class is also used for pointers for funtions that uses...
3
by: Mike L | last post by:
This is a WinForm. After the code below is executed, my data grid only shows a plus sign. I click the plus sign and the word table is shown. I click on the word table, and my columns are shown...
6
by: peter.xiau | last post by:
I found that std::vector<int> v(10) ; will automatically initiallize every elem to 0 in the vector, I check the source code (VS.NET2003), and I found a line of code like this *T = new T() ; ...
1
by: Steven Prasil | last post by:
When I run/debug a program with Console.out.write statements inside and the program execution reaches this statement then a new console/command prompt window (this with black background) is opened...
1
by: ranabhavin2 | last post by:
Hi, on button click I want to open new window each time. Currently when I m click on button second time then my new window is replaced with my original window. We can do it in hyperlink by ...
6
by: MarkoBBC | last post by:
Hi everyone, First a brief description of my form: I have a subform within a main form. In my subform, I have a listbox displaying address information by firm name. A user first has to select a...
2
by: MLH | last post by:
I have an A97 form with Allow Edits, Allow Deletions and Allow Additions properties set. Scrolling through records will eventually take me to the end of the records and one more PgDn will take me...
4
by: Wolfman | last post by:
http://javascript.internet.com/img/new-to-you/new.gif Hi all Upon seeking to differentiate new content from old in an HTML list based upon when each user last visited, I began researching "new to...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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
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.