?
Solved

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

Posted on 2001-06-20
10
Medium Priority
?
299 Views
Last Modified: 2008-02-26
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
Comment
Question by:FlSteve
[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
  • 2
  • 2
  • 2
  • +3
10 Comments
 
LVL 6

Expert Comment

by:PsychoDazey
ID: 6211788
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
 
LVL 6

Expert Comment

by:PsychoDazey
ID: 6211798
Sorry, put that code in the on click event of the command button.
0
 
LVL 7

Expert Comment

by:lmerrell
ID: 6211814
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
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 7

Expert Comment

by:lmerrell
ID: 6211837
The IsLoaded function will only work for instances within the same session of the database, not for other users.
0
 
LVL 14

Accepted Solution

by:
mgrattan earned 400 total points
ID: 6212074
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
 
LVL 1

Expert Comment

by:dhinkle
ID: 6214137
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
 

Author Comment

by:FlSteve
ID: 6214243
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
 
LVL 1

Expert Comment

by:dhinkle
ID: 6214268
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
 
LVL 14

Expert Comment

by:mgrattan
ID: 6215101
Glad to help Steve!

Mike
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

765 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