Solved

Make datasheet "read only"

Posted on 2006-11-18
11
222 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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.

778 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