Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent OnCurrent from running when opening form? 1

Status
Not open for further replies.

Ally72

Programmer
Nov 12, 2001
31
GB
I have an option group on a continuous form, where if the value = 2 already (on loan), I want it to either give a message saying that the machine is out on loan and cannot be edited via this form, OR to completely disable the option group for that machine.

The way I've done it so far is:
Code:
Private Sub Form_Current()
    Select Case Me.fraMachStatus
        Case 2
            msgbox "Machine is out on loan.  _
               You cannot change status here.", _
                    vbExclamation, "Restricted Action"
            Me.AllowEdits = False
        Case Else
            Me.AllowEdits = True
        
    End Select
End Sub

This appeared to work okay, but now it's giving me the msgbox when I open the form. Is there a way of saying:

Code:
If form is being opened Then
     don't Run Current Event 
Else
     Run Current Event
End If

Have played around with
[/code]If Me.OnOpen then
Exit Sub
Else ...[/code]

but get Run-time error 13, Type mismatch.

Does anyone know how to get round this please? Any suggestions gratefully received. (Using A'97)
 
Well, what do you want to happen if the machine is out on loan for the record that is displayed when you open the form?

One way to prevent this message box is to always guarantee that the machine is not on loan for the record displayed when opening the form. (i.e. open the form to a new record) Maq [americanflag]
<insert witty signature here>
 
It's a continuous form, therefore all records are on one page, displaying the status of machines, ie:

ID Type ... ... Status (Option Group)
123 ... ... ... . Free / Gone for Repair / Retired

Out on loan is not an option, but I have another text box next to the option group, which displays &quot;Out on loan to Patient Name&quot;

If a machine is out on loan then I want the clicking of the option group to display the message that they can't change the status there, or alternatively, to disable the option group for that record.
 
In your first post, you said that &quot;out on loan&quot; was an option (option 2). When exactly do you want this msgbox to pop up? When option 2 is selected in the option group, or only when the text box says &quot;out on loan&quot;?

Regardless of whether or not this is a continuous form or a single record display you still need to decide what should happen when the selected record meets your criteria for a msgbox when the form opens. The best way to prevent a msgbox is still to just open the form to a new record. If this isn't possible, then there are work-arounds but please be sure the &quot;work-arounds&quot; don't allow your user to edit a record they shouldn't be editing. Maq [americanflag]
<insert witty signature here>
 
Sorry I haven't made this very clear.

MachineStatusID is the Control Source of the option group where the value of 2 = On Loan.

Because I didn't want the user to have even the option of changing that value on this form (as it's done when the machine is allocated to a patient in the patient's clinic form), I didn't see the point in having a button for it, so didn't make one for it, just had the text box visible IF the machine was on loan, saying who it was on loan to.

What I meant by it's not an option is it's not there as an option for the user to change, but the value itself is part of the same control source of the option group.

What I want to happen is, if the value of MachineStatusID = 2 (out on loan) and the user tries to change it, for the msgbox to appear that they can't change it via that form.

Are you saying that if I go to a new record when I open the form that this should be ok? I did just try it but can't get my syntax correct.

 
Here's what I would suggest. There may be more efficient ways of doing this, and if it was a single form rather than continuous forms, I would definitely do it differently, but this should meet your needs.

Dim JustOpened as integer 'Note put this at the stop of the form's module. Not in any subroutine.
___________________________________________________
Private Sub Form_Open()
JustOpened = 1
End Sub
___________________________________________________
Private Sub Form_Current()
If Me!fraMachStatus = 2 then
If JustOpened = 0 then
msgbox &quot;Machine is out on loan. _
You cannot change status here.&quot;, _
vbExclamation, &quot;Restricted Action&quot;
End If
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If
JustOpened = 0
End Sub
Maq [americanflag]
<insert witty signature here>
 
That's excellent, works fine. Thank you very much for your patience and time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top