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)?
- Dim stDocName As String
-
Dim stMainForm As String
-
Dim stLinkCriteria As String
-
-
stDocName = "IURs: subform"
-
-
'****************** The following Line will NOT Save theRecord ******************
-
'Forms![Patient_IUR_Overview]![IURs Abbreviated: subform].Form.Dirty = False
-
'********************************************************************************
-
-
'******************* The following Lines WILL Save the Record *******************
-
'If Me.Dirty Then Me.Dirty = False
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
-
'********************************************************************************
-
-
stLinkCriteria = "[IURs.IUR Index]=" & Me![IUR Index]
-
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
20 3481
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: - Forms![<Main Form>]![<Sub-Form>].Form.Dirty = False
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: - Private Sub Open_IUR_Subform_Click()
-
On Error GoTo Err_Open_IUR_Subform_Click
-
-
Dim stDocName As String
-
Dim stMainForm As String
-
Dim stLinkCriteria As String
-
-
stMainForm = "Patient_IUR_Overview"
-
stSubForm = "IURs Abbreviated: subform"
-
stDocName = "IURs: subform"
-
-
'Forms![<stMainForm>]![<stSubForm>].Form.Dirty = False
-
'Forms![stMainForm]![stSubForm].Form.Dirty = False
-
'Forms![<stSubForm>]![<stDocName>].Form.Dirty = False
-
'Forms![stSubForm]![stDocName].Form.Dirty = False
-
-
stLinkCriteria = "[IURs.IUR Index]=" & Me![IUR Index]
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
Exit_Open_IUR_Subform_Click:
-
Exit Sub
-
-
Err_Open_IUR_Subform_Click:
-
MsgBox Err.Description
-
Resume Exit_Open_IUR_Subform_Click
-
-
End Sub
-
The "OpenForm" thing works great; I just included it in the interest of completeness.
Use the Syntax that I showed you in Post# 2, namely: - Forms![Patient_IUR_Overview]![IURs Abbreviated: subform].Form.Dirty = False
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."
Where is Pre-Admitting IURs originating from?
That's the name of the database itself. I forget where that's set.
Anyone else have any ideas to help me with this?
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. - Forms![Patient_IUR_Overview]![IURs Abbreviated: subform].Form.Dirty = False
Oh, thanks, Adezii! Here's the front end.
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.
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?
Okay, here's both the front end and a safe back end. I surely appreciate your help with this!
That seems to have done the trick! I see that the code is not at all the same:
didn't work: - Forms![Patient_IUR_Overview]![IURs Abbreviated: subform].Form.Dirty = False
did work: - 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?
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).
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.
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...
- Dim stDocName As String
-
Dim stMainForm As String
-
Dim stLinkCriteria As String
-
-
stDocName = "IURs: subform"
-
-
'****************** The following Line will NOT Save theRecord ******************
-
'Forms![Patient_IUR_Overview]![IURs Abbreviated: subform].Form.Dirty = False
-
'********************************************************************************
-
-
'******************* The following Lines WILL Save the Record *******************
-
'If Me.Dirty Then Me.Dirty = False
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
-
'********************************************************************************
-
-
stLinkCriteria = "[IURs.IUR Index]=" & Me![IUR Index]
-
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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....
|
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...
|
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...
|
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() ;
...
|
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...
|
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 ...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
| |