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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Form In New Record But Want So Not Able to Edit 1

Status
Not open for further replies.

shelby55

Technical User
Jun 27, 2003
1,229
CA
Hello

I would like a form to open up on a new record BUT not have that record be editable until the user selects "new record". This might sound odd but because the user could be going into the form to search for a record to edit (there is an edit button as well) I want the step of adding a new record to be deliberate. Right now on the OnLoad even of the form I have
Code:
Private Sub Form_Load()
biRet = MousewheelOff
DoCmd.GoToRecord , , acNewRec
Me.AllowEdits = False
End Sub

The above does open up at a new record but I am able to enter data without having to select the Add button which I don't want. Thanks.

 
Hi

I'm not sure what you're asking? Do you mean set the Allow Additions, Allow Deletions, Allow Edits to all be "no" and then they enabled via the button codes?

Thanks.
 
How are ya shelby55 . . .

[blue]Me.AllowEdits = False[/blue] doesn't work on a new record! See the [blue]lock[/blue] property of the controls ... aka put the cursor on the property line and hit F1.

Your Thoughts? . . .

See Ya . . .

Be sure to see FAQ219-2884 Worthy Reading! [thumbsup2]
Also FAQ181-2886 Worthy Reading! [thumbsup2]
 
Hey Duane

Can you please not respond to my posts if you aren't going to provide me with any assistance? I understand not giving me answers or just providing code without making me work for it because getting me to think will help me understand the concepts better BUT answering questions with questions or being cryptic with one line answers that don't tell me anything isn't even close to useful. I'm already somewhat frustrated by the time I post here because I've looked in other areas but just not getting it, then I'm pleased to see someone has answered, only to find the response is just someone appearing to be messing with me. I get it, you're smarter than me but unless you are willing to help please don't respond.

Thanks for the response, AceMan...sorry but I'm still not understanding how this will help me? From what I can tell from recordslock property, a new record is automatically locked when a record is being edited but then why is it that I can edit it without hitting the "add record" button? Also, on the Add Record button that I created I also have a function that looks for the last number used and uses that number + 1 for the ID_Number which is my own auto number function. So if someone can save the record without entering data or without having a unique ID_Number then that's not good either. Thanks for any assistance you can provide. Thanks.

 
Shelby55,
Both AceMan and I suggested you look at the properties of the controls rather than the form. We both assumed you would understand this. All of your bound controls have both "locked" and "Enabled" properties. If your code loops through the bound controls and set the Locked property to Yes/True, they will not be editable.

This might or might not work based on your needs.

Duane
Hook'D on Access
MS Access MVP
 
shelby55 . . .

Following is a general routine you can use to lock/unlock the form. Be sure to add a question mark [blue]?[/blue] (no quotations please) to the [blue]tag[/blue] property of each control you wish to lock. Then copy/pase the following to the code module of the form:
Code:
[blue]Public Sub LockCtls(flg As Boolean)
   Dim ctl As Control
   
   For Each ctl In Me.Controls
      If ctl.Tag = "?" Then
         ctl.Locked = flg
      End If
   Next

End Sub[/blue]

Next we detect when the focus moves to the [blue]add new line[/blue] using the forms [blue]On Current[/blue] event and lock the controls. So copy/paste the following line to your forms [blue]On Current[/blue] event:

Code:
[blue]   Call LockCtls(Me.NewRecord)[/blue]

Next in your add New button you'll have:

Code:
[blue]   Call LockCtls(False)[/blue]

[blue]Your Thoughts? . . .[/blue]

See Ya . . .

Be sure to see FAQ219-2884 Worthy Reading! [thumbsup2]
Also FAQ181-2886 Worthy Reading! [thumbsup2]
 
Hi

Thank you, thank you, this is excellent and just want I wanted and it works amazingly.
 
Hi

Sorry but it's me again. In another post I received assistance with creating a search form with multiple search fields. The user will double click records in the list which then opens up the appropriate form (could be one of 3 forms I have).

I've got this search working well but only if I remove the "DoCmd.GoToRecord , , acNewRec" line from the Load event of the form. So how can I discern between a new record versus an existing one to direct if I went to go to new record or not?

Thanks.
 
Test the Me.NewRecord property.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I'd use the OpenArgs property to know if the form is launched by the search button or not.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top