Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2007
    Posts
    6

    Unanswered: Simple question?

    Hopefully this is a simple question. I have an Access 2002 database. In the database I have the main table storing the records. My question is I have the first record in the table the default record if any of the searches don't find anything and its information says "default" for all of its fields. Is there a way to protect that record from being modified and still let all the other records be modified?

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Well......If you are displaying your records through a Form you could, I suppose, do this:

    Place into the OnCurrent event for your Records display Form:

    Code:
    If Me.myFormsTextBoxNameThatHoldsTheAutoNumberID = DFirst("[mytableAutoNumberFieldName]", "myTableName") Then 
       Call LockRecord (Me, True)
    Else
       Call LockRecord (Me, False)
    End If
    Then in a database Code Module place this Public Function:

    Code:
    Public Function LockRecord(ByRef Frm As Form, ByVal LockIt As Boolean) As Boolean
       'Returns True if Form Record is Locked
       'and False if Form Record is Not Locked.
       If LockIt = True Then   
          Frm.AllowAdditions = False
          Frm.AllowDeletions = False
          Frm.AllowEdits = False
          LockRecord = True
       Else
          Frm.AllowAdditions = True
          Frm.AllowDeletions = True
          Frm.AllowEdits = True
          LockRecord = False
       End If
    End Function
    .
    Last edited by CyberLynx; 10-18-07 at 23:53.
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  3. #3
    Join Date
    Jul 2007
    Posts
    6
    Thanks, I'm new to this. My table name is "Monday". The autonumber field name is "RecordNo". The default record's autonumber is "1". I'm having trouble getting the code to work. It keeps giving me a compile error in VB.
    Here is what I have:

    Private Sub Form_Current()
    If Me.id = DFirst("[RecordNo]", "Monday") Then
    Call LockRecord(Me, True)
    Else
    Call LockRecord(Me, False)
    End If

    End Sub

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    My deepest appologies...There should be no Me.ID unless of course the field you have on Form which displays your record ID number (the AutoNumber field) happens to have the name.... ID. I have edited and corrected the code above (take another look ).

    If you've used the MS-Access Form Wizard to auto create your Form based from your Table, then chances are this textbox will be named RecordNo. if this is the case then the code line should read like:

    If Me.RecordNo = DFirst("[RecordNo]", "Monday") Then

    On your Form, find the TextBox that which displays the AutoNumber for your records then look in the properties window and get the name used for that field. Place that name after the Me. and all should be OK.

    Any more problems.....then please let me know.

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  5. #5
    Join Date
    Jul 2007
    Posts
    6
    First of all thanks for your help.

    I'm still having issues with this.
    I'm getting a Compile error: Expected variable or procedure, not module on the Call LockRecord(Me, True) line.

    Here is what I have:

    Private Sub Form_Current()
    If Me.RecordNo = DFirst("[RecordNo]", "Monday") Then
    Call LockRecord(Me, True)
    Else
    Call LockRecord(Me, False)
    End If

    End Sub




    Public Function LockRecord(ByRef Frm As Form, ByVal LockIt As Boolean) As Boolean

    'Returns True if Form Record is Locked
    'and False if Form Record is Not Locked.
    If LockIt = True Then
    Frm.AllowAdditions = False
    Frm.AllowDeletions = False
    Frm.AllowEdits = False
    LockRecord = True
    Else
    Frm.AllowAdditions = True
    Frm.AllowDeletions = True
    Frm.AllowEdits = True
    LockRecord = False
    End If


    End Function

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Try changing
    Code:
    Call LockRecord(Me, True)
    To
    Code:
    LockRecord Me, True
    George
    Home | Blog

  7. #7
    Join Date
    Jul 2007
    Posts
    6
    Thanks, but I still get the same error

  8. #8
    Join Date
    Nov 2003
    Posts
    1,487
    ahhhh...I can't see anything real obvious here as to why you're getting this particular error.

    In any case...try a simple test. Let's try and forget about the LockRecord function and place the function code directly into the OnCurrent event ... just to see what happens (copy and paste the code below).

    Code:
    Private Sub Form_Current()
       If Me.RecordNo = DFirst("[RecordNo]", "Monday") Then
           Me.AllowAdditions = False
           Me.AllowDeletions = False
           Me.AllowEdits = False
        Else
           Me.AllowAdditions = True
           Me.AllowDeletions = True
           Me.AllowEdits = True
       End If
    End Sub
    I really don't like doing things that way. I prefer not to have a lot of code in Events but try it anyway.

    It would be nice to actually see the error and the error number, a screenshot maybe.

    Perhaps try and get rif of the ByRef and ByVal statements within the function declaration line and see what happens then as well.

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  9. #9
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    Public Function LockRecord(ByVal frmName As String, _
                               ByVal LockIt  As Boolean)
    
          Forms(frmName).AllowAdditions = LockIt 
          Forms(frmName).AllowDeletions = LockIt 
          Forms(frmName).AllowEdits = LockIt 
    
    End Function
    Try the above. Note that the different way of referencing the form and the declaration of fmrName is now ByVal As String.
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •