A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Create a button to save/update record OR add new record



 
 
Thread Tools Display Modes
  #11  
Old August 10th, 2005, 05:38 PM
DrewTheFather
external usenet poster
 
Posts: n/a
Default

Here's the code:

Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click


Dim MyDb As Database, Myrec As Recordset
Set MyDb = CodeDb() ' Current MDB
Set Myrec = MyDb.OpenRecordset("Select * From Office Where Office_ID = " &
Me.Office_Code)
If Myrec.EOF Then ' No records
Myrec.AddNew
Else
Myrec.Edit ' record exist
End If

Myrec!Office_Name = Me.Office_Name
Myrec!Business_City = Me.Business_City
Myrec!Business_ST_Add = Me.Business_address
Myrec!Business_ZIP = Me.Business_ZIP
Myrec!Mailing_City = Me.Mailing_City
Myrec!Business_ZIP = Me.Business_ZIP
Myrec!Mailing_ST_Add = Me.Mailing_Address
Myrec.Update


Exit_SAVE_BUTTON_Click:
Exit Sub

Err_SAVE_BUTTON_Click:
MsgBox Err.Description
Resume Exit_SAVE_BUTTON_Click

End Sub
  #12  
Old August 10th, 2005, 05:51 PM
DrewTheFather
external usenet poster
 
Posts: n/a
Default

Upon a little further investigation, when I tried to change the Myrec.Edit
statment, after I type "Myrec." a drop down menu is displayed with a list of
statement values/functions, and oddly enough, the "Edit" statement is not
present, but "Save" and "Update" are. I tried using both of those in the
place of "Edit" and it complies fine, but when I click the "SAVE" button, I
get the error "Too few Parameters. Expected 1."

Don't know if this would help or not.

  #13  
Old August 10th, 2005, 11:02 PM
Ofer
external usenet poster
 
Posts: n/a
Default

Sorry for the delay
I have never seen this, that the edit doesn't apear on the list, so try
removing the edit line, It could be that its by default set to edit, unless
you tell it other wise.

Cange that :
If Myrec.EOF Then ' No records
Myrec.AddNew
Else
Myrec.Edit ' record exist
End If

To:
If Myrec.EOF Then ' No records
Myrec.AddNew
End If


"DrewTheFather" wrote:

Upon a little further investigation, when I tried to change the Myrec.Edit
statment, after I type "Myrec." a drop down menu is displayed with a list of
statement values/functions, and oddly enough, the "Edit" statement is not
present, but "Save" and "Update" are. I tried using both of those in the
place of "Edit" and it complies fine, but when I click the "SAVE" button, I
get the error "Too few Parameters. Expected 1."

Don't know if this would help or not.

  #14  
Old August 11th, 2005, 11:16 AM
Ofer C via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

Found the problem, in the reference locate the dao3.6 strait after the Access
11 reference.
If you have an ole automation refernce, the dao should be before it.

DrewTheFather wrote:
Here's the code:

Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click

Dim MyDb As Database, Myrec As Recordset
Set MyDb = CodeDb() ' Current MDB
Set Myrec = MyDb.OpenRecordset("Select * From Office Where Office_ID = " &
Me.Office_Code)
If Myrec.EOF Then ' No records
Myrec.AddNew
Else
Myrec.Edit ' record exist
End If

Myrec!Office_Name = Me.Office_Name
Myrec!Business_City = Me.Business_City
Myrec!Business_ST_Add = Me.Business_address
Myrec!Business_ZIP = Me.Business_ZIP
Myrec!Mailing_City = Me.Mailing_City
Myrec!Business_ZIP = Me.Business_ZIP
Myrec!Mailing_ST_Add = Me.Mailing_Address
Myrec.Update

Exit_SAVE_BUTTON_Click:
Exit Sub

Err_SAVE_BUTTON_Click:
MsgBox Err.Description
Resume Exit_SAVE_BUTTON_Click

End Sub



--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200508/1
  #15  
Old August 11th, 2005, 04:32 PM
DrewTheFather
external usenet poster
 
Posts: n/a
Default

In my References option, there is no record of an Access 11 reference....I
tried browsing, but could not find it. Is this causing the problem?


"Ofer C via AccessMonster.com" wrote:

Found the problem, in the reference locate the dao3.6 strait after the Access
11 reference.
If you have an ole automation refernce, the dao should be before it.


  #16  
Old August 11th, 2005, 05:48 PM
Ofer
external usenet poster
 
Posts: n/a
Default

You need reference to MSACC.OLB you might have a different Access, 8 or
something
If so put the other reference, dao3.6, just after it

"DrewTheFather" wrote:

In my References option, there is no record of an Access 11 reference....I
tried browsing, but could not find it. Is this causing the problem?


"Ofer C via AccessMonster.com" wrote:

Found the problem, in the reference locate the dao3.6 strait after the Access
11 reference.
If you have an ole automation refernce, the dao should be before it.


  #17  
Old August 11th, 2005, 06:16 PM
DrewTheFather
external usenet poster
 
Posts: n/a
Default

I have a reference to MSACC9.OLB directly followed by a reference to the DAO
3.6

From what I have looked at and tested, correct me if I'm wrong, but the
problem lies in the SET of Myrec.

This is error starting to wear on me.

"Ofer" wrote:

You need reference to MSACC.OLB you might have a different Access, 8 or
something
If so put the other reference, dao3.6, just after it

"DrewTheFather" wrote:

In my References option, there is no record of an Access 11 reference....I
tried browsing, but could not find it. Is this causing the problem?


"Ofer C via AccessMonster.com" wrote:

Found the problem, in the reference locate the dao3.6 strait after the Access
11 reference.
If you have an ole automation refernce, the dao should be before it.


  #19  
Old August 11th, 2005, 06:51 PM
DrewTheFather
external usenet poster
 
Posts: n/a
Default

I tried sending the file to you from two different addresses and it failed
due to the size of the Zip'ed file. Any other suggestions?


  #20  
Old August 11th, 2005, 08:19 PM
DrewTheFather
external usenet poster
 
Posts: n/a
Default

OK, so now I got the Save (update) working, now I'll be working on adding a
new record.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Report by using the current record in a form ember General Discussion 4 September 15th, 2005 02:48 PM
User Saving a Record else it deletes Carter Wexler Using Forms 1 August 2nd, 2005 11:57 PM
Design help, please SillySally Using Forms 27 March 6th, 2005 04:11 AM
Prevent Blank Records being written. Need Help. Robert Nusz @ DPS Using Forms 4 December 29th, 2004 05:15 PM
Open form, Edit button, etc Aniko Using Forms 14 July 25th, 2004 08:17 AM


All times are GMT +1. The time now is 02:40 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.