Lock Form until Certain Feild is Entered

adrienne_r30

Registered User.
Local time
Today, 17:45
Joined
Jan 20, 2015
Messages
48
I have a data entry form that I would like to lock all fields until the Contract Number is entered. Any one have any suggestions?

to see if I was on the right path I tried something very simple,
on current
if me.contract_num = null then
msgbox("enter contract number")
end if

but that didn't even work

thanks!
 
My vba knowledge is limited so perhaps use the below as a suggestion and see if it helps, perhaps someone else can confirm/improve on this!

Select the boxes you would like locked to begin with and right click --> Properties, under Data is the Locked option.

Then I think an 'On Change' event of

Code:
if not isnull (me.textbox.value) then
me.otherbox.enabled = true
me.anotherbox.enabled = true

end if
 
I'd do this with another form. It would simply have an input on it for the Contract Number and a button. They fill in the Contract Number and click the button and it it takes them to the form you currently have. They click the button without a Contract Number you yell at them to put one in.
 
Hi,
I can think of 2 options:

1) The form has a Locked property: Me.Locked. It's value is false by default, you can set it to true.
For unlocking - have a button click open an InputBox, witch ca receive the contract number. If correct - it will set Me.Locked = False.

2) Each Control has a locked prpert. You can set Relevant controls to ctrlName.Locked = True, and have a textBox for receiving the contract number. you can have a button click, or textBox click, check for the correct contract number.

For unlocking Controls you can use For Each loop on the form's Controls collection.

ATB!
 
I occasionally do this.

set each control to enabled=false, except the one you want

explicitly is probably easiest

ctrl0.enabled = true
ctrl1.enabled = false
ctrl2.enabled = false
ctrl3.enabled = false
ctrl4.enabled = false
ctrl5.enabled = false
ctrl6.enabled = false


in the after update event for the first control, enable any controls you now want to be enabled.

ctrl1.enabled = true
ctrl2.enabled = true


etc.
 
Thank you all for your helpful suggestions, they are awesome. I decided to go with the enabled method, which works great. I am hoping that someone can help me with one last thing. Its along the same lines but if we can't solve it I can start a new thread for it. So I turned enable to no for everything that I needed to. when I open my form, the Contract Number has focus, so I put the code in the lost focus event. But if I type a contract number, lose focus, then delete the contract number, when I close the form it saves the record with no contract number, which is obviously not what I want to do. so I put some code in the exit command button. Most of it works fine, but I cant seem to find where to put the End IF codes to make it all work perfectly. This is what I am trying to do, if the contract number is blank, ask if the user would like to enter a number or not. If no, then it deletes the record and closes the form, if yes, it takes the user to the contract number. it all works fine, but if there is a contract number, the form doesn't close, it doesn't do anything.

Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
If IsNull(Me.[NYSDOT_Contract_No]) Then

If MsgBox("Contract Number has to be Entered. Press Yes to Enter a Contract Number or No to Delete This Record", vbQuestion + vbYesNo) = vbYes Then
Cancel = True
Me.NYSDOT_Contract_No.SetFocus
End If
Else
If Me.Dirty Then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.Close
End If
If Me.Dirty Then Me.Dirty = False
DoCmd.Close
Exit_cmdExit_Click:
Exit Sub
Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click
End If
End Sub
 
Perfect, I got it...Thanks so much everyone

Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
If IsNull(Me.[NYSDOT_Contract_No]) Then

If MsgBox("Contract Number has to be Entered. Press Yes to Enter a Contract Number or No to Delete This Record", vbQuestion + vbYesNo) = vbYes Then
Cancel = True
Me.NYSDOT_Contract_No.SetFocus

Else
If Me.Dirty Then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.Close
Else
DoCmd.Close
End If
End If
Else
If Me.Dirty Then Me.Dirty = False
DoCmd.Close
End If

Exit_cmdExit_Click:
Exit Sub
Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click
End Sub
 

Users who are viewing this thread

Back
Top Bottom