I have programmed with MS Access frequently and am familiar with VBA.
Can you give sample code for a button to Add and one for Del and how
to go about it.
I think once I see it, I'll be on the way to getting this
accomplished.
Thanks Again
Greg
Greg,
Here are the macros. Put them in a regular module, and assign them to keyboard shortcuts, if
desired (Tools - Macros - Macros - Options). Or put a buttons on the sheet (drawing
toolbar), and assign them to the macros.
Sub InsertRow()
If ActiveCell.Locked = True Then
MsgBox "You can't insert a row here", vbOKOnly, ""
Exit Sub
End If
ActiveSheet.Unprotect Password:="aa"
ActiveCell.EntireRow.Insert
ActiveSheet.Protect Password:="aa"
End Sub
Sub DeleteRow()
If ActiveCell.Locked = True Then
MsgBox "You can't remove a row here", vbOKOnly, ""
Exit Sub
End If
ActiveSheet.Unprotect Password:="aa"
ActiveCell.EntireRow.Delete
ActiveSheet.Protect Password:="aa"
End Sub
These routines will allow inserting/deleting rows based on the active cell being protected.
If there are other cells in the sheet that are unprotected, they'll allow
inserting/deleting, which is undesirable. If there are such other cells, we'll need another
means of checking. Post back if that's the case.
If you're not using passwords in your sheet protection, remove the Password:="aa" part.

Signature
Regards from Virginia Beach,
Earl Kiosterud
www.smokeylake.com
-----------------------------------------------------------------------
I have programmed with MS Access frequently and am familiar with VBA.
Can you give sample code for a button to Add and one for Del and how
to go about it.
I think once I see it, I'll be on the way to getting this
accomplished.
Thanks Again
Greg
On May 10, 12:20 pm, "Earl Kiosterud" <some...@nowhere.com> wrote:
> Greg,
>
[quoted text clipped - 50 lines]
>
> - Show quoted text -
Greg - 10 May 2008 21:37 GMT
Thanks Earl
This is what I came up with I had some additional issues that had to
be addressed:
Private Sub CommandButton1_Click()
'Insert Row Button
If ActiveCell.Row > 6 And ActiveSheet.UsedRange.Rows.Count >
ActiveCell.Row Then
Me.Unprotect
Rows(ActiveCell.Row).Insert
Me.Protect
Else
Beep
End If
End Sub
Private Sub CommandButton2_Click()
'Delete Row Button
If ActiveCell.Row > 6 And ActiveSheet.UsedRange.Rows.Count >
ActiveCell.Row Then
Me.Unprotect
Rows(ActiveCell.Row).Delete
Me.Protect
Else
Beep
End If
End Sub
Thanks Again
Greg
Earl Kiosterud - 11 May 2008 04:53 GMT
Greg,
Looks good, except the UsedRange can get bloated. When you've deleted rows, it still can
show a used range larger than it currently is. Closing and reopening the workbook is the
usual way to reset it. It sounds as though your records go to the bottom of your used
range, and there are no totals and other junk below them (your Access roots are showing!
:) ). In that case it probably doesn't matter if anyone inserts or deletes rows beyond your
last record.

Signature
Regards from Virginia Beach,
Earl Kiosterud
www.smokeylake.com
-----------------------------------------------------------------------
> Thanks Earl
>
[quoted text clipped - 27 lines]
> Thanks Again
> Greg
Greg - 14 May 2008 17:08 GMT
Thanks Earl
Actually I do have totals at the bottom of the worksheet. I guest I
could move them up to the top.
The problem now is that the range does expand causing the worksheet to
get larger than I would like.
Is there a way to lock in the totals row to the specific location (say
row50). O create some kind of restrictive
window. Or do I need to build logic into my existing code to make the
adjustments somehow in response to the
button being pressed?
Thanks
Greg
> Greg,
>
[quoted text clipped - 42 lines]
>
> - Show quoted text -