By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,660 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,660 IT Pros & Developers. It's quick & easy.

Custom New...Edit...Save buttons

P: n/a
I have a dilema here that I'm hoping some one can help me out with.

On my forms I have some basic New, Edit, Save, Delete, Undo buttons on
them. When first opened all controls on the form are not enabled. When
you hit one of the buttons certain controls enable and some don't
depending on the function. My dilema is with the New button and in turn
the Save button.

I would rather the user click the "New" button to add a record instead
of clicking the next button, or the page down. So the first thing I
tried was to turn the AllowAddtions to Off. Then the first part of my
code when "New" is clicked turns it on, then adds new record. Now the
user would hit the "Save" button to basically set the enable to all
controls to false and then turn the AllowAdditions back off. The
problem is when it turns the AllowAdditions to off, the form jumps back
to record # 1. So I thought I would add code to have it go to the Last
Record after all the other code finished, but that only works on a new
record, if I hit "Save" after editing a record, I wouldn't want it to
jump to the Last record.

I decided to forget about the above method and just go back to allowing
additions, maybe I can fix that later with security settings or
something.

But I found one other annoyance after adding a New Record and then
Saving it. I'm using code for my own custom First, Last, Next, Previous
buttons and a Label that shows the Record x of y info. This always says
New Record until I leave the record and come back.

Is there anyway to have turning off AllowAddtions to not take you to
record # 1 or is there a way to have the Record x of y label not always
say New Record.

Or any other method of doing what I'm looking for.

It's kind of confusing so if you have any questions, ask me.

Thanks,
Ken Mylar

Apr 28 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Ken Mylar wrote:
I have a dilema here that I'm hoping some one can help me out with.

On my forms I have some basic New, Edit, Save, Delete, Undo buttons on
them. When first opened all controls on the form are not enabled. When
you hit one of the buttons certain controls enable and some don't
depending on the function. My dilema is with the New button and in turn
the Save button.

I would rather the user click the "New" button to add a record instead
of clicking the next button, or the page down. So the first thing I
tried was to turn the AllowAddtions to Off. Then the first part of my
code when "New" is clicked turns it on, then adds new record. Now the
user would hit the "Save" button to basically set the enable to all
controls to false and then turn the AllowAdditions back off. The
problem is when it turns the AllowAdditions to off, the form jumps back
to record # 1. So I thought I would add code to have it go to the Last
Record after all the other code finished, but that only works on a new
record, if I hit "Save" after editing a record, I wouldn't want it to
jump to the Last record.

I decided to forget about the above method and just go back to allowing
additions, maybe I can fix that later with security settings or
something.

But I found one other annoyance after adding a New Record and then
Saving it. I'm using code for my own custom First, Last, Next, Previous
buttons and a Label that shows the Record x of y info. This always says
New Record until I leave the record and come back.

Is there anyway to have turning off AllowAddtions to not take you to
record # 1 or is there a way to have the Record x of y label not always
say New Record.

Or any other method of doing what I'm looking for.

It's kind of confusing so if you have any questions, ask me.

Thanks,
Ken Mylar

When you save the record, store the ID. Then you can have similar code to
Dim rst As Recordset
set rst = Me.RecordsetClone
rst.Findfirst "ID = " & lngStoredID
Me.bookmark = rst.Bookmark
This will move you back to the record last added.

Apr 28 '06 #2

P: n/a
Thanks for your help! I'm not sure how to go about storing the ID when
I save the record. I have a bunch of forms that all the same exact
buttons, so I created all my code as a Public Function, so I didn't
have to keep duplicating all the same code. The Save function is shown
below, I hope this can work on a global level because it sounds like
exactly what I need. If not, I may need to take the Save function down
to form level.

Thanks,
Ken
************************************************** *****************************
Public Function cmdSave_Click(frm As Form)
On Error GoTo Err_cmdSave_Click

Dim ctl As Control

For Each ctl In frm.Controls
If ctl.Tag = "Unlockable" Then
ctl.Enabled = False
ElseIf ctl.Tag = "AlwaysLocked" Then
ctl.Enabled = False
End If
Next ctl

DoCmd.RunCommand acCmdSaveRecord

frm.cmdFirst.Enabled = True
frm.cmdPrevious.Enabled = True
frm.cmdNext.Enabled = True
frm.cmdLast.Enabled = True
frm.cmdClose.Enabled = True
frm.cmdEdit.Enabled = True
frm.cmdNew.Enabled = True
frm.cmdDelete.Enabled = True
frm.btnUndo.Enabled = False
frm!cmdEdit.SetFocus
frm.cmdSave.Enabled = False
frm.AllowAdditions = False
frm.DataEntry = False

Exit_cmdSave_Click:
Exit Function

Err_cmdSave_Click:
Call LogError(Err.Number, Err.Description,
"cmdSave_Click()", "modFormNavigation")
Resume Exit_cmdSave_Click
End Function

Apr 28 '06 #3

P: n/a
Ken Mylar wrote:
Thanks for your help! I'm not sure how to go about storing the ID when
I save the record.
Go to the top of the code. Under your Option statemets (I assume you
have at least OptionExplicit), enter something like
Dim lngStoreID As Long

In the BeforeUpdate or AfterUpdate event of the form, store the ID. Ex:
lngStoreID = Me.ID

See code comments below. BTW, it assumes your id is numeric long.

I have a bunch of forms that all the same exact buttons, so I created all my code as a Public Function, so I didn't
have to keep duplicating all the same code. The Save function is shown
below, I hope this can work on a global level because it sounds like
exactly what I need. If not, I may need to take the Save function down
to form level.

Thanks,
Ken
************************************************** *****************************
Public Function cmdSave_Click(frm As Form)
On Error GoTo Err_cmdSave_Click

Dim ctl As Control

For Each ctl In frm.Controls
If ctl.Tag = "Unlockable" Then
ctl.Enabled = False
ElseIf ctl.Tag = "AlwaysLocked" Then
ctl.Enabled = False
End If
Next ctl

DoCmd.RunCommand acCmdSaveRecord

frm.cmdFirst.Enabled = True
frm.cmdPrevious.Enabled = True
frm.cmdNext.Enabled = True
frm.cmdLast.Enabled = True
frm.cmdClose.Enabled = True
frm.cmdEdit.Enabled = True
frm.cmdNew.Enabled = True
frm.cmdDelete.Enabled = True
frm.btnUndo.Enabled = False
frm!cmdEdit.SetFocus
frm.cmdSave.Enabled = False
frm.AllowAdditions = False
frm.DataEntry = False
It appears that when you set dataentry to false, it "requery's" the
form. In that case, put the code
Dim rst As Recordset
set rst = Me.RecordsetClone
rst.Findfirst "ID = " & lngStoredID
Me.bookmark = rst.Bookmark
rst.close
set rst = Nothing
here.

Exit_cmdSave_Click:
Exit Function

Err_cmdSave_Click:
Call LogError(Err.Number, Err.Description,
"cmdSave_Click()", "modFormNavigation")
Resume Exit_cmdSave_Click
End Function

Apr 28 '06 #4

P: n/a
"Ken Mylar" <km****@elch.org> wrote in news:1146241989.849337.156600
@i39g2000cwa.googlegroups.com:
I have a dilema here that I'm hoping some one can help me out with.

On my forms I have some basic New, Edit, Save, Delete, Undo buttons on
them.


When you get this perfected are you going to sell it so the rest of us
don't have to use the trusted, safe, convenient, quick Access way that MS
spent millions to create and maintain, and that we paid for when we bought
Access?

--
Lyle Fairfield
Apr 28 '06 #5

P: n/a
They are the same buttons that the wizard dropped in place. With the
same code behind them except for some GUI changes.

I don't think my Access made Undo button should always look like it can
be pressed as defaulted. And that I don't like my edit button to be
enabled when I'm already editing or my Save button to look enabled when
I haven't changed anything or my New button to be enabled when I'm
editing or entering a new record. I also don't want my users to be able
to leave the current record while editing or entering a record.

All the above wasn't too difficult to take care of and I had one thing
that bugged me, which was why I posted the message.

Ken

Lyle Fairfield wrote:
When you get this perfected are you going to sell it so the rest of us
don't have to use the trusted, safe, convenient, quick Access way that MS
spent millions to create and maintain, and that we paid for when we bought
Access?

--
Lyle Fairfield


Apr 28 '06 #6

P: n/a
That did the trick, Thanks.

Ken

Apr 28 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.