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

Alter DataEntry property in open form 1

Status
Not open for further replies.

bikerted

Technical User
Nov 7, 2003
221
0
0
GB
Hi Everyone,

This is perhaps a slightly different take on the mouse scroll problem, which I'm aware that there are many links FAQs and what have you. My Favouritesfrm is based on a query, and to create new Favourites I click a button containing the following (not elegant nevertheless it works and clears the unbound controls in which the user enters new Favourites criteria):
Code:
Private Sub Label47_Click()
Application.Echo False
DoCmd.Close acForm, "Favouritesfrm"
DoCmd.OpenForm "Favouritesfrm"
DoCmd.GoToRecord , , acNewRec
Forms!Favouritesfrm!FavouriteDetails.SetFocus
Application.Echo True
End Sub
This takes me to the new record, but ofcourse the mouse scroll can move away from it causing a record to be overwritten. I tried setting the DataEntry property to false within this code, and also within the Current event of the form, but then the error message indicates that the form is not recognised. I pursued this because, in the former case, I found it was possible to scroll records until I hit the new record and then the scroll locked. Is it not possible by definition to move to a new record and set Data Entry to false in the same context? Anyone's thoughts/criticisms would be valued.

Thank you in anticipation.

Ted.
 
Ted,

Maybe I'm missing something here, but don't you want the DataEntry property to be set to True (i.e. the form opens showing only a blank record)? I believe you can set this with the [blue]acFormAdd[/blue] constant in the DataMode argument of the OpenForm method.

HTH,

Ken S.
 
Ken,

Thanks for your reply. Actually, it's (you've guessed it) slightly more complicated than that. My form creates "Favourite" entries to be entered on my main form in one touch to save the laborius re-entering of the same data, so I have on it a means to look up and edit existing Favourites and for creating new ones and therefore it opens in edit/add modes anyway. The form opens with blank unbound controls on which I can either view by selection existing Favourites or enter a new one by clicking the appropriate button. I have hidden the controls which "accept" data input on the form, but they are still in the background and still "scrollable". What I wanted to do is go to the new record and freeze editing or better still change the form to data entry only temporarily. I just tried to insert AllowEdits = false in the above procedure but the error 2467 indicates that "the expression you entered refers to an object that is closed or doesn't exist". Looks like I'm stuffed?

Ted.
 
Hi, Ted,

Okay, DataEntry = True (not false!) causes the form to open to a new, blank record - existing records are not displayed. And the acFormAdd constant in the DataMode argument of the OpenForm method overrides the saved form settings and opens the form in DataEntry mode.

From the help files on Data Entry mode:

[tt] The DataEntry property uses the following settings.

Setting Visual Basic Description
--------------------------------------
Yes True The form opens showing only a blank record.
No False (Default) The form opens showing existing records.[/tt]

From the help files for the OpenForm method:

[tt] DataMode [blue]Optional AcFormOpenDataMode[/blue]. The data entry mode for the form. This applies only to forms opened in Form view or Datasheet view

AcFormOpenDataMode can be one of these AcFormOpenDataMode constants.
[blue]acFormAdd[/blue] The user can add new records but can't edit existing records.
acFormEdit The user can edit existing records and add new records.
acFormPropertySettings default
acFormReadOnly The user can only view records.
If you leave this argument blank (the default constant, acFormPropertySettings, is assumed), Microsoft Access opens the form in the data mode set by the form's AllowEdits, AllowDeletions, AllowAdditions, and DataEntry properties.[/tt]

HTH,

Ken S.
 
Thanks Ken,

I have read this through before, but your highlighting and attention to detail has helped me understand it better, which makes me wonder whether (by way of contradicting all I've just said)why the following didn't prevent edits after opening the form:
Code:
Application.Echo False
DoCmd.Close acForm, "Favouritesfrm"
DoCmd.OpenForm "Favouritesfrm", acFormAdd
DoCmd.GoToRecord , , acNewRec
Forms!Favouritesfrm!FavouriteDetails.SetFocus
Application.Echo True

Perhaps I still haven't grasped it?

Ted
 
Ted,

You've placed the constant as the wrong argument of the OpenForm method. Try this:
Code:
DoCmd.OpenForm "Favouritesfrm", , , , acFormAdd
From the help files:

[tt] The OpenForm method carries out the OpenForm action in Visual Basic.

expression.OpenForm(FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)

...

You can leave an optional argument blank in the middle of the syntax, but you must include the argument's comma. If you leave a trailing argument blank, don't use a comma following the last argument you specify.[/tt]

HTH,

Ken S.
 
Ken,

That now works, and of course it shows that I should have read the help files more carefully. Thank you so much for taking the trouble to explain it to me. I've learnt something new - again thanks to Tek-Tips and a very patient contributor.

Thank you,

Ted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top