[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

How to stop the form from opening from a second user....

Hello, stars,

Am trying to build an application that will be shared with about 4 or 5 users.  Want to allow them in this app to do other procedures.  I want to stop the option of successive users from using an Add Record form.  Here is what basically happens.  When they press a <Record Maintenance> button on the opening page, they are presented with all the current records in the database.  They can modify any field except the unique customized record number.  When they wish to add a new record to the table, they press a command button. A new form appears for input of this information.  While this form is open, I wish that no other user have the permission to open the form as the same customized number will be assigned.  That presents a conflict on closing one of the forms or loss of a number if the first user should cancel out the input.  How can I disable the command button if the Add button has a form open in another instance?

Thank you for stopping by and schooling me.

FlSteve
0
FlSteve
Asked:
FlSteve
  • 2
  • 2
  • 2
  • +3
1 Solution
 
PsychoDazeyCommented:
Function IsLoaded(ByVal strFormName As String) As Boolean
 ' Returns True if the specified form is open in Form view or Datasheet view.
   
    Const conObjStateClosed = 0
    Const conDesignView = 0
   
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
        If Forms(strFormName).CurrentView <> conDesignView Then
            IsLoaded = True
            msgbox"you cannot open this form at this time", vbokonly
        exit function
        else
         'open your form
        End If
    End If
   
End Function
0
 
PsychoDazeyCommented:
Sorry, put that code in the on click event of the command button.
0
 
lmerrellCommented:
You can use a table and add a record when the form is opened and the table is empty.  You could notify the user to try again later and Cancel the button click if the table has a record.  And then you would empty the table when exiting the form.

lmerrell
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
lmerrellCommented:
The IsLoaded function will only work for instances within the same session of the database, not for other users.
0
 
mgrattanCommented:
You can create a table that stores only the NEXT unique record number that has not yet been assigned.  Each time a user clicks a button to create a new record, the table that contains your number can be updated to have that number incremented.  For example:

Private Sub btnNewRec_Click()
Dim db as DAO.Database, rs as DAO.Recordset
Set db = Currentdb
Set rs = db.OpenRecordset("tblUniqueRecNo", dbOpenDynaset)

rs.MoveFirst
rs.Edit
rs!RecNo = rs!RecNo + 1
rs.Update
rs.Close
Set rs = Nothing
Set db = Nothing

End Sub

Using this method, you won't have to worry about restricting users from having the form open simultaneously.
0
 
dhinkleCommented:
mgratten's solution is the one I use. I have a system where 5 of the users are keying new records all day long so allowing only one add at a time is not an option. I store the last used number in a table and when Add Record is clicked it grabs the number, adds 1 and writes it back so the next user has access to it. you would still have the issue of lost numbers though if someone cancelled. That is not an issue for my system fortunately but if it is for you you'll have to come up with a way to handle it. Possibly if a user cancelled you could write that number to an unused numbers table. Then when you were getting your next number you would check for an entry in that table first. If one existed you could use the number then delete it and if none existed get your number from the other table.
0
 
FlSteveAuthor Commented:
OK, now that you have found my re-incarnation, you provided the code that I needed to get started, too.  Thanks, Mike.  You are exactly right about the IsLoaded function per instance.  Tried that and tried the disable of the command button.  But, in any successive instance, it did not apply.  This creating a table or inserting a record into a table makes good sense and I needed just a push on how to do this.  Thanks so much.  This is my first attempt with multiple users in which I need to lock a feature at one time.  

Also, the idea posed by another good fellow, of placing unused numbers in a suspense file is an excellent idea.  Have considered that concept and may just apply if the customer is willing to go with it.  Thank you for that suggestion.  

Thank all of you for stopping.   Some of us learned something and all had experiences to share.  

FlSteve  - Have a super day.

0
 
dhinkleCommented:
This is the code that I use to get the next number. May not be the best way but it works great. It lives in the OnClick event of the Add Record button

        Set db = CurrentDb()
        Set rst = db.OpenRecordset("tblMaxInsulationApplNo", dbOpenDynaset)
    'start the new record
        DoCmd.GoToRecord , , acNewRec
        cmdDeletePermit.Enabled = False
        cmdChangePermit.Enabled = False
        cmdPrintPermit.Enabled = False
        cmdMakePayment.Enabled = False

applno is the application number. I have to force a format on it but you would just need to set applno.value = rst!field.value

        ApplNo.Value = Format(Right(rst!MaxInsulationApplNo, 6) + 1, "000000")
 
write the used number back to the maxnumber table
       Do While Not rst.EOF
            rst.Edit
            rst![MaxInsulationApplNo] = ApplNo
            rst.Update
            rst.MoveNext
        Loop
        rst.Close
       
        Set rst = Nothing
        Set db = Nothing
0
 
mgrattanCommented:
Glad to help Steve!

Mike
0
 
amp072397Commented:
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now