Access Form Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • titli
    New Member
    • May 2010
    • 26

    #1

    Access Form Question

    Hi All,

    I have an application , with the following features.Recent ly facing some problem.

    At a certain point of time if a user had already run partfile , application displays file status as locked by the particular user.

    columns are filename , sourcedata present(checked /unchecked),want torun(same),onc ehasbeenrun(sam e),nameofperson WhoHasrunit(sam e)

    Step1 : On checking the "wanttorun" field for the first time by new user, an option appears saying "File is locked by user".
    Step2 : On clicking OK , the "wanttorun" field appears checked, no other change.
    Step3 : Again on clicking for the third time , the user column becomes empty.
    Step4 : Again on clicking for the fourth time it takes the new user name .



    I will somewhat display what my code looks liek on clicking of wanttorun check box.

    Code:
    Private Sub wanttoRun_Click()
        
        Dim db As Database
        Dim strSQL As String
        Dim rs As dao.Recordset
        Dim bbIstoRun As Boolean
        
    On Error GoTo wantToRunErr
        
        bbIstoRun = IsToRun
        
        Set db = CurrentDb
    
        strSQL = "SELECT * FROM tblFileExisting " & _
                 "WHERE FileNo = " & FileNo & " " & _
                 "AND date = #" & Format(Forms![frmMain].cboCOB, "DD/MMM/YYYY") & "#"
        Set rs = db.OpenRecordset(strSQL)
        Me.Requery
        With rs
            If .RecordCount > 0 Then
                .MoveFirst
                If bbIstoRun = True Then
                    If Not IsNull(!UserLock) And !UserLock <> "" Then
       MsgBox "File is already locked by " & !UserLock, , "Application"
                        
                        IsToRun.Value = False
                        GoTo IstoRunExit
                                        End If
                    ' It's not being locked, so lock it!!
                    .Edit
                    !UserLock = Environ$("UserName")
                    .Update
                Else
                    .Edit
                    !UserLock = Null
                    .Update
                End If
            End If
        End With
    
      
        Me.Requery
        Me.Repaint
        Forms("frmMain").Repaint
        
    IstoRunExit:
        On Error Resume Next
        Set db = Nothing
        Exit Sub
    
    IsToRunErr:
        MsgBox Err.Description, , "Application"
        Resume IstoRunExit
        
    End Sub
    Problem is only the first file in the list ,i.e first record, doesn't work normally , and fails at step 2 mentioned above.
    Say teh first file was run by someone, last column has his name, now i try to check it for running, i get message , locked by so n so , but then the check disappears unlike for other other files , in other records of the form.

    Is it that teh databse is corrupt..There' s nothing wrong with teh code i know, i have not amde any changes, it was working fine till yesterday.

    Thanks in advance !

    Titli
    Last edited by NeoPa; Aug 2 '10, 03:30 PM. Reason: Please use the [CODE] tags provided
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    Have you tried tracing through the code when you know it is about to behave erratically?

    Comment

    Working...