473,387 Members | 1,834 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.

Save new record to table

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
Expand|Select|Wrap|Line Numbers
  1. docmd.save, acForm "fdlgNewAccount" 'to keep the form open
  2. .....
  3. ..... code to do other things.
  4.  
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
Feb 24 '09 #1
12 29854
ChipR
1,287 Expert 1GB
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
Feb 24 '09 #2
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSaveNewPtAccount_Click()
  2. Dim strMsg As String
  3.  
  4. If IsNull([txtPT_ACCOUNT#]) Then
  5.     MsgBox "Patient Account number is required!", vbInformation, "REQUIRED FIELD!"
  6.     [txtPT_ACCOUNT#].SetFocus
  7.     Exit Sub
  8. ElseIf IsNull(txtUNIT_ADM_DATE) Then
  9.     MsgBox "Unit Admit Date is required!", vbInformation, "REQUIRED FIELD!"
  10.     [txtUNIT_ADM_DATE].SetFocus
  11.     Exit Sub
  12. ElseIf IsNull(cboFACILITY) Then
  13.     MsgBox "Facility is required!", vbInformation, "REQUIRED FIELD!"
  14.     [cboFACILITY].SetFocus
  15.     Exit Sub
  16. Else
  17.     DoCmd.Save acForm, "fdlgAddNewAccount" 'save new account# first in order to carry over account info to review form
  18.     strMsg = "Account: " & [txtPT_ACCOUNT#] & " " & [txtUNIT_ADM_DATE] & " has been added successuflly!"
  19.     If MsgBox(strMsg, vbInformation + vbOKOnly, "Record Added!") = vbOK Then
  20.         DoCmd.OpenForm "frmReview", , , , acFormAdd 'open reivew form as a new review
  21.         'carry over all demographic info and account # info
  22.         [Forms]![frmReview]![txtMEDREC] = [Forms]![fdlgAddNewAccount]![txtMEDREC]
  23.         [Forms]![frmReview]![txtPATLNM] = [Forms]![fdlgAddNewAccount]![txtPATLNM]
  24.         [Forms]![frmReview]![txtPATFNM] = [Forms]![fdlgAddNewAccount]![txtPATFNM]
  25.         [Forms]![frmReview]![txtPT_ACCOUNT#] = [Forms]![fdlgAddNewAccount]![txtPT_ACCOUNT#]
  26.         [Forms]![frmReview]![txtUNIT_ADM_DATE] = [Forms]![fdlgAddNewAccount]![txtUNIT_ADM_DATE]
  27.         [Forms]![frmReview]![txtFACILITY] = [Forms]![fdlgAddNewAccount]![cboFACILITY]
  28.         [Forms]![frmReview]![txtAGE] = [Forms]![fdlgAddNewAccount]![txtAGE]
  29.         [Forms]![frmReview]![txtPATSEX] = [Forms]![fdlgAddNewAccount]![txtPATSEX]
  30.         [Forms]![frmReview]![txtICD9] = [Forms]![fdlgAddNewAccount]![txtICD9]
  31.         [Forms]![frmReview]![txtUsername] = [Forms]![fdlgAddNewAccount].[txtUsername]
  32.         [Forms]![frmReview]![txtROOM#].SetFocus
  33.         [Forms]![frmReview]![cmdCancel].Enabled = True
  34.         [Forms]![frmReview]![cmdCancel].Visible = True
  35.         [Forms]![frmReview]![cmdSave].Enabled = True
  36.         [Forms]![frmReview]![cmdSave].Visible = True
  37.         [Forms]![frmReview]![lblAddMode].Visible = True
  38.         [Forms]![frmReview]![cmdClearVAPScreen].Enabled = True
  39.         DoCmd.Close acForm, "fdlgAddNewAccount"
  40.         DoCmd.Close acForm, "frmPatient", acSaveNo
  41.     End If
  42. End If
  43. End Sub
  44.  
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
Feb 24 '09 #3
ChipR
1,287 Expert 1GB
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.
Feb 24 '09 #4
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
Feb 24 '09 #5
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!
Feb 24 '09 #6
ChipR
1,287 Expert 1GB
@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.
Feb 24 '09 #7
I'll try and will let you know if it works.

bluemoon
Feb 24 '09 #8
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.
Expand|Select|Wrap|Line Numbers
  1. 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.
Feb 24 '09 #9
missinglinq
3,532 Expert 2GB
"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)>
Feb 25 '09 #10
NeoPa
32,556 Expert Mod 16PB
It's less straightforward even than that Linq.
Expand|Select|Wrap|Line Numbers
  1. 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.
Feb 25 '09 #11
missinglinq
3,532 Expert 2GB
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)>
Feb 25 '09 #12
NeoPa
32,556 Expert Mod 16PB
I was looking at the OP's db in delete record.
Feb 25 '09 #13

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

Similar topics

7
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...
2
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...
4
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...
1
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,...
2
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...
3
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...
0
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...
1
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...
0
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...
1
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...
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: 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$) { } ...
0
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...
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
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...
0
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...
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.