By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,473 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,473 IT Pros & Developers. It's quick & easy.

Access Form Question

P: 26
Hi All,

I have an application , with the following features.Recently 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),wanttorun(same),oncehasbeenrun(same),na meofpersonWhoHasrunit(same)

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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub wanttoRun_Click()
  2.  
  3.     Dim db As Database
  4.     Dim strSQL As String
  5.     Dim rs As dao.Recordset
  6.     Dim bbIstoRun As Boolean
  7.  
  8. On Error GoTo wantToRunErr
  9.  
  10.     bbIstoRun = IsToRun
  11.  
  12.     Set db = CurrentDb
  13.  
  14.     strSQL = "SELECT * FROM tblFileExisting " & _
  15.              "WHERE FileNo = " & FileNo & " " & _
  16.              "AND date = #" & Format(Forms![frmMain].cboCOB, "DD/MMM/YYYY") & "#"
  17.     Set rs = db.OpenRecordset(strSQL)
  18.     Me.Requery
  19.     With rs
  20.         If .RecordCount > 0 Then
  21.             .MoveFirst
  22.             If bbIstoRun = True Then
  23.                 If Not IsNull(!UserLock) And !UserLock <> "" Then
  24.    MsgBox "File is already locked by " & !UserLock, , "Application"
  25.  
  26.                     IsToRun.Value = False
  27.                     GoTo IstoRunExit
  28.                                     End If
  29.                 ' It's not being locked, so lock it!!
  30.                 .Edit
  31.                 !UserLock = Environ$("UserName")
  32.                 .Update
  33.             Else
  34.                 .Edit
  35.                 !UserLock = Null
  36.                 .Update
  37.             End If
  38.         End If
  39.     End With
  40.  
  41.  
  42.     Me.Requery
  43.     Me.Repaint
  44.     Forms("frmMain").Repaint
  45.  
  46. IstoRunExit:
  47.     On Error Resume Next
  48.     Set db = Nothing
  49.     Exit Sub
  50.  
  51. IsToRunErr:
  52.     MsgBox Err.Description, , "Application"
  53.     Resume IstoRunExit
  54.  
  55. 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
Aug 2 '10 #1
Share this Question
Share on Google+
1 Reply


NeoPa
Expert Mod 15k+
P: 31,768
Have you tried tracing through the code when you know it is about to behave erratically?
Aug 2 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.