Solved

Make datasheet "read only"

Posted on 2006-11-18
11
220 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 4

Author Comment

by:billcute
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 4

Author Comment

by:billcute
Comment Utility
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
Comment Utility
or...you just want me to place your code specifically at the On Current code..

Regards
Bill
0
 
LVL 4

Author Comment

by:billcute
Comment Utility
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
Comment Utility
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
Comment Utility
LPurvis,
This is good. Thanks

Regards
Bill
0
 
LVL 44

Expert Comment

by:Leigh Purvis
Comment Utility
Glad you like it.  Welcome.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now