Solved

Make datasheet "read only"

Posted on 2006-11-18
11
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

617 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