Solved

Make datasheet "read only"

Posted on 2006-11-18
11
225 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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.

751 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