hi,
I've written this code to save the record without closing the form
so instead of write the code as
docmd.close, acform "fdlgNewAccount",,,acSaveYes -
docmd.save, acForm "fdlgNewAccount" 'to keep the form open
-
.....
-
..... code to do other things.
-
Does it cause problem with multiple users using the database at the same time?
is there a better way to save a new record into the table but still have the form open?
can someone please help
12 29854
The DoCmd.Save is saving the FORM, not the record.
I didn't test this, but an Access MVP said elsewhere:
If you really need to do this, you can write
RunCommand acCmdSaveRecord
or
If Me.Dirty Then Me.Dirty = False
Hi,
Actually I was able to save record into the table just fine. It's just that when my users use the database, sometime, after they have entered all data into the form, click on OK button, then nothing happen. But sometimes they were able to add without any problem.
Here is my complete code. -
Private Sub cmdSaveNewPtAccount_Click()
-
Dim strMsg As String
-
-
If IsNull([txtPT_ACCOUNT#]) Then
-
MsgBox "Patient Account number is required!", vbInformation, "REQUIRED FIELD!"
-
[txtPT_ACCOUNT#].SetFocus
-
Exit Sub
-
ElseIf IsNull(txtUNIT_ADM_DATE) Then
-
MsgBox "Unit Admit Date is required!", vbInformation, "REQUIRED FIELD!"
-
[txtUNIT_ADM_DATE].SetFocus
-
Exit Sub
-
ElseIf IsNull(cboFACILITY) Then
-
MsgBox "Facility is required!", vbInformation, "REQUIRED FIELD!"
-
[cboFACILITY].SetFocus
-
Exit Sub
-
Else
-
DoCmd.Save acForm, "fdlgAddNewAccount" 'save new account# first in order to carry over account info to review form
-
strMsg = "Account: " & [txtPT_ACCOUNT#] & " " & [txtUNIT_ADM_DATE] & " has been added successuflly!"
-
If MsgBox(strMsg, vbInformation + vbOKOnly, "Record Added!") = vbOK Then
-
DoCmd.OpenForm "frmReview", , , , acFormAdd 'open reivew form as a new review
-
'carry over all demographic info and account # info
-
[Forms]![frmReview]![txtMEDREC] = [Forms]![fdlgAddNewAccount]![txtMEDREC]
-
[Forms]![frmReview]![txtPATLNM] = [Forms]![fdlgAddNewAccount]![txtPATLNM]
-
[Forms]![frmReview]![txtPATFNM] = [Forms]![fdlgAddNewAccount]![txtPATFNM]
-
[Forms]![frmReview]![txtPT_ACCOUNT#] = [Forms]![fdlgAddNewAccount]![txtPT_ACCOUNT#]
-
[Forms]![frmReview]![txtUNIT_ADM_DATE] = [Forms]![fdlgAddNewAccount]![txtUNIT_ADM_DATE]
-
[Forms]![frmReview]![txtFACILITY] = [Forms]![fdlgAddNewAccount]![cboFACILITY]
-
[Forms]![frmReview]![txtAGE] = [Forms]![fdlgAddNewAccount]![txtAGE]
-
[Forms]![frmReview]![txtPATSEX] = [Forms]![fdlgAddNewAccount]![txtPATSEX]
-
[Forms]![frmReview]![txtICD9] = [Forms]![fdlgAddNewAccount]![txtICD9]
-
[Forms]![frmReview]![txtUsername] = [Forms]![fdlgAddNewAccount].[txtUsername]
-
[Forms]![frmReview]![txtROOM#].SetFocus
-
[Forms]![frmReview]![cmdCancel].Enabled = True
-
[Forms]![frmReview]![cmdCancel].Visible = True
-
[Forms]![frmReview]![cmdSave].Enabled = True
-
[Forms]![frmReview]![cmdSave].Visible = True
-
[Forms]![frmReview]![lblAddMode].Visible = True
-
[Forms]![frmReview]![cmdClearVAPScreen].Enabled = True
-
DoCmd.Close acForm, "fdlgAddNewAccount"
-
DoCmd.Close acForm, "frmPatient", acSaveNo
-
End If
-
End If
-
End Sub
-
I tried to leave the form "Patient Account" open when I save the record because I want to carry some demographic fields over to the new form (frmReview)
Any idea?
Thanks for your help
bluemoon
I'm not quite sure what you mean. What goes wrong when you take out the "DoCmd.Close acForm, "frmPatient", acSaveNo"?
Also "If MsgBox(strMsg, vbInformation + vbOKOnly, "Record Added!") = vbOK Then" doesn't really make sense, since there are no other options. You can get rid of the If.
Hi,
I need to have "DoCmd.Close acForm, "frmPatient", acSaveNo ", because there is another form behind the fdldNewPatientAccount form.
What happen here is user will enter a new pt, then prompt user to enter new account, then prompt uer to enter new review. One to many relationship.
The reason I have the If vbOK is because
DoCmd.Save acForm, "fdlgAddNewAccount" 'save new account#'
then "save recorded " cofirm message, with vbOK button,
user will click on OK, then
...execute my code which is transfer all the fields (demograhpic data, account#, etc) from the frmPatient and fdlgPtAccount to the frmReview
My question here is I am not sure if I save the NEW PT ACCOUNT correctly, since it's where user has problem sometimes. When confirm message poped up, they click on OK, but nothing happen, instead of moving to the frmReview, it did nothing.
Thanks!
bluemoon
Hi,
In addition, I did try to get rid of the If since there is only option, but it did not solve the problem, so I just left it there.
thanks!
@bluemoon9
Like I said in Post #2, the DoCmd.Save does not save the new record. Fix that and see if you still have problems. If so, hopefully I can help tomorrow if some one else doesn't first.
I'll try and will let you know if it works.
bluemoon
NeoPa 32,556
Expert Mod 16PB
Chip is definitely on the right lines here BlueMoon.
I did a little digging to find how (best) to save records in a form. - If Me.Dirty Then Me.Dirty = False
I fuller reference can be found on Allen Browne's site at Losing data when you close a form. It's not as straightforward as I expected, and certainly not as it should be.
"It's not as straightforward as I expected, and certainly not as it should be."
And it just keeps on keeping on, NeoPa!
You definitely have to explicitly force a record save with either RunCommand acCmdSaveRecord
or If Me.Dirty Then Me.Dirty = False
before closing the form with DoCmd.Save or records that fail validation will simply be dumped without any warning messages!
And DoCmd.Save is, of course, the code the Command Button Wizard has generated for a Close button up thru version 2003!
After knowing about this problem for years they decided to fix it for version 2007. The Wizard now generates the code If Me.Dirty Then Me.Dirty = False DoCmd.Save
The problem with this is that if you now use it on a form in 2007 that has no records, i.e. an unbound form, such as a menu/switchboard form, the line If Me.Dirty Then Me.Dirty = False
generates an error, because an unbound form doesn't have a Dirty Property! If they had used RunCommand acCmdSaveRecord there wouldn't have been a problem, no error would have resulted!
As I said, the problem keeps on keeping on!
Linq ;0)> NeoPa 32,556
Expert Mod 16PB
It's less straightforward even than that Linq. - RunCommand acCmdSaveRecord
Would have been my recommendation had it not failed spectacularly when I tried it in normal use. I understand that the form itself must be selected (not the case after a button is clicked) if it's to work.
It seems that setting Dirty = False (horribly crappy and unobvious - actually worse as it's obviously doing something else - except it's not) is the only reliable way to do it in most circumstances.
I've never had a problem with RunCommand acCmdSaveRecord either in 2000 or 2003, although I confess, I generally use If Me.Dirty Then Me.Dirty = False simply because it's the first way I learned to force a save.
I have no problem placing RunCommand acCmdSaveRecord behind a button and having it work appropriately, although I would not use it in this manner, myself, never using "Save" buttons, as so many people feel compelled to do!
What exact scenario were you using when you ran into problems?
Linq ;0)> Sign in to post your reply or Sign up for a free account.
Similar topics
by: Larry |
last post by:
Hi,
I have unbelievable problems just to save a record!
I make an input to a record in a subform, which has a
temporary table as its recordsource.
When I am done, and want to save the...
|
by: crjunk |
last post by:
I'm trying to write a piece of code that will programatically save a
record automatically without me having to add a new ' Row.Item("ADD1")
= txtAdd1.Text.Trim.ToUpper ' type command each time I...
|
by: tarafinlay |
last post by:
Hi all,
I am new to access and am finding it a bit unintuitive having worked
with SQL server in the past... And I am in a bit of a hurry because my
employer wants me to crank something out which...
|
by: tkhouk |
last post by:
I'm using Access 2003... I'm date and time stamping a record (to fields in a table) whenever it is accessed in the form and then the control is then sent back to the lookup box. While on the form,...
|
by: voroojak |
last post by:
Hi
How can i put save record and next record in one button.
in my save record i put the calculation of the text boxes. i have a total field that the sum of the other field is in there and it wil be...
|
by: Angus |
last post by:
I have a web page with a toolbar containing a Save button. The Save
button can change contextually to be a Search button in some cases.
Hence the button name searchsavechanges.
The snippet of...
|
by: bloukopkoggelmander |
last post by:
Hi All wonderfull brains!
Right I have two questions after my last very successfull thread. I have tried looking these up on the net, but no luck.
Scenario 1 is : I have a bound form with bound...
|
by: TonyJ |
last post by:
Hello!
I'm using VS2005.
I'm looking at ADO.NET and have found some test tutorial solution on
microsoft MSDN.
The one that I'm looking at now is called Walkthrough: Saving Data to a
Database...
|
by: burttonboarder |
last post by:
I'm working on a rails project where I have a table called people and a table called addresses.
Each person can have many addresses. I've created a form which includes fields from both the People...
|
by: gdixon |
last post by:
Greetings To All!
I am using a Access 2003 and my programing skills are of the cut and paste variety. This means begining programming skills and on a good day perhaps middle of the road...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
| |