Solved

Make datasheet "read only"

Posted on 2006-11-18
11
223 Views
Last Modified: 2008-02-01
The On Load event code of frmFilingDates below automatically update the last and most recent "row" of fields to tblFiligDates and display the full datasheet format as shown below - The update to the last row and most current row is based current "quarter" information. This code works fine as expected.

However, I want to add a feature that when frmFilingDate form opens, .....all records from rows 1 - 10 will be "read only" except the last row fields (e.g row 11) .......which would be the only "editable" row available to user.

I tried to adapt the "Me.allowedit.enable = False" to the row columns but was not successful with it.

I will appreciate any assistance in achieving the desired goal to the datasheet.
 ' *************
'Private Sub Form_Load()
   
    Dim iQQ As Integer
    Dim iYY As Integer
   
    'Get current quarter/year based on system date
    iQQ = DatePart("q", Date)
    iYY = DatePart("yyyy", Now())

    'If current date is not last of last quarter
    If DateIsLastQuarterDate(Now()) = False Then

        'If quarter 1 then for previous quarter, we need to subtract the  year also
        If iQQ = 1 Then
            iQQ = 4
            iYY = iYY - 1
        Else
            iQQ = iQQ - 1
        End If
    End If

        Dim rs As DAO.Recordset
       
        Set rs = Me.RecordsetClone
        rs.FindFirst "QtrNo = " & iQQ & " AND YearNum = " & iYY
        'Matching record for current qq/yy does not exist, then go in addmode
        If rs.NoMatch = True Then
            DoCmd.GoToRecord , , acNewRec
        ' **************************
         'If in addmode
        If Me.NewRecord = True Then
            'Initialise variables with defaults
            Me.txtFDID = DMax("FDID", "tblFilingDates") + 1
            Me.txtGetDateFiling = Date
            Me.txtQtr = iQQ
            Me.txtYear = iYY
            Me.txtFDID = DMax("FDID", "tblFilingDates") + 1
            Me.txtGetDateFiling.SetFocus
            Me.Dirty = False
        Else
            'Load record
            Me.Bookmark = rs.Bookmark
        End If
        rs.Close
        Set rs = Nothing
    'Otherwise edit mode and changes made
    ElseIf Me.Dirty = True Then
        Me.Dirty = False
    Else
        MsgBox "There are no pending changes that meet update criteria", vbInformation, FRM_TITLE
    DoCmd.Close
    End If
End Sub
' ******************

Datasheet of frmFilingDate:

FDID      QtrNo      YearNum      DateFiled
1      1      2004      4/14/2004           '<<<<---- Wants each row "Read Only"
2      2      2004      7/14/2004           '<<<<---- Wants each row "Read Only"
3      3      2004      10/14/2004         '<<<<---- Wants each row "Read Only"
4      4      2004      1/14/2005           '<<<<---- Wants each row "Read Only"
5      1      2005      4/14/2005           '<<<<---- Wants each row "Read Only"
6      2      2005      7/14/2005           '<<<<---- Wants each row "Read Only"
7      3      2005      09/14/2005         '<<<<---- Wants each row "Read Only"
8      4      2005      1/14/2006           '<<<<---- Wants each row "Read Only"
9      1      2006      4/14/2006           '<<<<---- Wants each row "Read Only"
10      2      2006      7/14/2006           '<<<<---- Wants each row "Read Only"

11            3               2006         09/30/2006         '<<<<---- Current Updated fields -
                                                                                          'Make this row fields the only "editable fields"
0
Comment
Question by:billcute
  • 6
  • 5
11 Comments
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17971748
Could you just add this as your Current event?

Private Sub Form_Current()
    Me.AllowEdits = Me.FDID > 10
End Sub
0
 
LVL 4

Author Comment

by:billcute
ID: 17971806
LPurvis,
There will always be an increment of the row every quarter for example, when Quarter 4 expires, and frmFilingDate is opened, the tblFilingDate will receive an increment.
So in one year, tblFilingDates will receve four updates...but I want to lock all rows as they increment but always leave the last and most recent row editable...

In this case, your code will not work as expected......for example if we have rows 11, 11, 13, 14 and so on...in tblFilingdates
...then these rows will all be editable if your code is utilized.

Regards
Bill
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17971831
So what are you saying... that the FDID will increment beyond 1-11...

e.g. ID 215 might be the 11th row - and you want that to be updateable...

Of that when there are more than 11 rows - only row number 11 should be updateable?

Or that in such a scenario - the final row (whatever number row it may be) should be updateable.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 4

Author Comment

by:billcute
ID: 17971925
when there are more than 11 rows - then lock row 11 like others
..if the newest row is row 12, then it should be updateable?
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17971944
OK.  One of, likely, many ways

Private Sub Form_Current()
   
    Dim intCount As Integer
   
    If Me.NewRecord Then Exit Sub
   
    With Me.RecordsetClone
        .MoveLast
        intCount = .RecordCount
        .Bookmark = Me.Bookmark
        Me.AllowEdits = .AbsolutePosition = intCount - 1
        .Close
    End With
   
End Sub
0
 
LVL 4

Author Comment

by:billcute
ID: 17972001
Ok,
Would you be kind to blend your code with my "On Load code" above... especially here...

'If in addmode
        If Me.NewRecord = True Then
            'Initialise variables with defaults
            Me.txtFDID = DMax("FDID", "tblFilingDates") + 1
            Me.txtGetDateFiling = Date
            Me.txtQtr = iQQ
            Me.txtYear = iYY
            Me.txtFDID = DMax("FDID", "tblFilingDates") + 1
            Me.txtGetDateFiling.SetFocus
            Me.Dirty = False
        Else
            'Load record
            Me.Bookmark = rs.Bookmark
        End If
        rs.Close
        Set rs = Nothing
    'Otherwise edit mode and changes made
    ElseIf Me.Dirty = True Then
        Me.Dirty = False
    Else
        MsgBox "There are no pending changes that meet update criteria", vbInformation, FRM_TITLE
    DoCmd.Close
    End If
' *************

Regards
Bill
0
 
LVL 4

Author Comment

by:billcute
ID: 17972003
or...you just want me to place your code specifically at the On Current code..

Regards
Bill
0
 
LVL 4

Author Comment

by:billcute
ID: 17972017
sorry,
,,,your code works as is...

one more thing....
In the absolute position, is it possible to further lock the last row FDID, QtrNo and Yearnum fields but allow the "Datefiled" field the only updateable field?

Regards
Bill
0
 
LVL 44

Accepted Solution

by:
Leigh Purvis earned 500 total points
ID: 17972106
You'll be best off setting the locked property for the FDID, QtrNo and Yearnum controls to Yes in form Design view (as they'll always be locked).
Then have

Private Sub Form_Current()
   
    Dim intCount As Integer
   
    If Me.NewRecord Then Exit Sub
   
    With Me.RecordsetClone
        .MoveLast
        intCount = .RecordCount
        .Bookmark = Me.Bookmark
        Me.Datefiled.Locked = .AbsolutePosition < intCount - 1
        .Close
    End With
   
End Sub
0
 
LVL 4

Author Comment

by:billcute
ID: 17972761
LPurvis,
This is good. Thanks

Regards
Bill
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17973031
Glad you like it.  Welcome.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question