Locking a Form???

G

Guest

Hello,

I have researched this topic on here and haven't found what I'm looking for
although there are a lot of information about locking.

This is what I want to do.

I have a form, with two comman buttons, Add Record and Edit Record. I want
that when the user opens the form for all the fields to be locked. When the
user, clicks the Add Record Button, all the fields are unlocked and they are
able to enter a record. When the user clicks on the Edit Record Button, I
have a form that pops up asking for them to enter their name and the current
date, this works fine. I want that after they enter this information, and
they click the okay button (which is really a save record button I created
using the command button wizard), I want the fields unlocked and they can
edit the existing data.

Is this possible? Can anyone please help me with this or point me in the
right direction? Do you need any further data? I'm new to this as I have
state numerous times, and very much appreciates your help.

Thanks.
 
G

Guest

Hi, Trini.

Use the form's AllowEdits & AllowAdditions properties. Set them to No in
form design view, and toggle them on as appropriate.

' Edit Record code
Me.AllowEdits = True

' Add Record code
Me.AllowAdditions = True
DoCmd.GotoRecord , , acNewRec
Me.YourFirstControl.SetFocus

Set them back to False in the OnCurrent event:

If Not Me.NewRecord Then
Me.AllowAdditions = False
Me.AllowEdits = False
End If

Sprinks
 
G

Guest

Sprinks,

First of all, I want to thank you for your response, however, I'm not quite
understanding what you said. I have the following questions:

1. What do you mean when you said "toggle them on as appropriate"? How do
I do this, what is the code?

2. The code you gave me, where or what event do I put them on? Is that all
the code or do I have to add it to existing code (I don't have any)?

I'm sorry, but if you can do the codes and explain what you are doing in
detail, I would greatly appreciate it.

Thanks.
 
G

Guest

Hi, Trini. Sorry for not being more explicit. The code I gave was to be
added to the OnClick event procedures of your Edit Record button and Add
Record buttons, respectively. Both "toggle on" the appropriate form property.

Please post your current event procedures for these buttons, and for the OK
button of the pop-up form, and I'll show you where these commands should be
inserted.

Sprinks
 
G

Guest

Sprinks,

This is the code for my Add Button

Private Sub btnADD_LEAK_Click()
On Error GoTo Err_btnADD_LEAK_Click

If Not bolCheckDuplicate Then
DoCmd.GoToRecord , , acNewRec
End If
bolCheckDuplicate = False

Exit_btnADD_LEAK_Click:
Exit Sub

Err_btnADD_LEAK_Click:
MsgBox Err.Description
Resume Exit_btnADD_LEAK_Click

End Sub

This is the code for my Edit Button

Private Sub Command63_Click()
On Error GoTo Err_Command63_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Form1"

stLinkCriteria = "[LEAKID]=" & Me![RWO #]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command63_Click:
Exit Sub

Err_Command63_Click:
MsgBox Err.Description
Resume Exit_Command63_Click

End Sub

This is my code for my Okay button on the pop-up form

Private Sub cmbOK_Click()
On Error GoTo Err_cmbOK_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close acForm, Me.Name

Exit_cmbOK_Click:
Exit Sub

Err_cmbOK_Click:
MsgBox Err.Description
Resume Exit_cmbOK_Click

End Sub

This is my code for my Cancel button on the pop up form

Private Sub cmdcCancelClose_Click()
If Me.Dirty Then
Me.Undo
End If
DoCmd.Close acForm, Me.Name
End Sub

I think thats about all you asked for. I thank you for your responses and
your time.
 
G

Guest

Hi, Trini.

Change the code to your add button to:

Private Sub btnADD_LEAK_Click()
On Error GoTo Err_btnADD_LEAK_Click

If Not bolCheckDuplicate Then
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
Me.YourFirstControl.SetFocus
End If
bolCheckDuplicate = False

Exit_btnADD_LEAK_Click:
Exit Sub

Err_btnADD_LEAK_Click:
MsgBox Err.Description
Resume Exit_btnADD_LEAK_Click

End Sub

Change your OK button code to:

Private Sub cmbOK_Click()
On Error GoTo Err_cmbOK_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Forms!YourOriginalForm.AllowEdits = True
DoCmd.Close acForm, Me.Name

Exit_cmbOK_Click:
Exit Sub

Err_cmbOK_Click:
MsgBox Err.Description
Resume Exit_cmbOK_Click

End Sub

Hope that helps.
Sprinks
 
G

Guest

Sprinks,

I forgot to mention it, but my original form has a subform. In the subform
is where the buttons are, and where the data is being inputted. Does that
make a difference in the coding?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top