Ryan-
Here's the Help topic on OpenForm:
The OpenForm method carries out the OpenForm action in Visual Basic.
expression.OpenForm(FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)
expression Required. An expression that returns one of the objects in the Applies To list.
FormName Required Variant. A string expression that's the valid name of a form in the current database. If you execute Visual Basic code containing the OpenForm method in a library database, Microsoft Access looks for the form with this name first in the library database, then in the current database.
| AcFormView can be one of these AcFormView constants. |
| acDesign |
| acFormDS |
| acFormPivotChart |
| acFormPivotTable |
| acNormal default. Opens the form in Form view. |
| acPreview If you leave this argument blank, the default constant (acNormal) is assumed. |
FilterName Optional Variant. A string expression that's the valid name of a query in the current database.
WhereCondition Optional Variant. A string expression that's a valid SQL WHERE clause without the word WHERE.
| AcFormOpenDataMode can be one of these AcFormOpenDataMode constants. |
| acFormAdd |
| acFormEdit |
| acFormPropertySettings default |
| acFormReadOnly 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. |
| AcWindowMode can be one of these AcWindowMode constants. |
| acDialog |
| acHidden |
| acIcon |
| acWindowNormal default If you leave this argument blank, the default constant (acWindowNormal) is assumed. |
OpenArgs Optional Variant. A string expression. This expression is used to set the form's OpenArgs property. This setting can then be used by code in a form module, such as the Open event procedure. The OpenArgs property can also be referred to in macros and expressions.
For example, suppose that the form you open is a continuous-form list of clients. If you want the focus to move to a specific client record when the form opens, you can specify the client name with the openargs argument, and then use theFindRecord method to move the focus to the record for the client with the specified name.
This argument is available only in Visual Basic.
The article fails to mention that you can also use named arguments. I hate counting commas, so I tend to write my OpenForm calls using named arguments, like this:
DoCmd.OpenForm FormName:="MyForm", View:=acNormal, DataMode:=acFormEdit, _
WindowMode:=acWindowNormal, OpenArgs:="Hello", WhereCondition:="MyKey = " & Me.MyKey
Note that I did NOT put the arguments in the same order as specified in the method description. That's one of the beauties of using named arguments - you can put them in any order.
John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications
SQL Queries for Mere Mortals
(Paris, France)
On Feb 10, 2014, at 2:49 PM, 易健福 <ryan.paschal@gmail.com> wrote:
I'm trying to use the docmd.OpenForm method. I have successfully pass an argument using the OpenArgs parameter. However, I can't determine the data mode, whether it is opened in acFormAdd, acFormEdit, or acFormReadOnly. Can this method replace all the codes you wrote earlier? Or, do I still need those codes?Sorry, I am really a beginner here. I understand some programming logic & coding, but I don't understand how the Access' VBA behave.RyanOn Mon, Feb 10, 2014 at 8:36 PM, 易健福 <ryan.paschal@gmail.com> wrote:Well, I'm trying to make 2 forms: Employee List & Employee Details.
Employee List will be in datasheet view & read-only, while the Employee Details will be in form view, locked by default until edit button is clicked. There'll be a combo box to navigate through employee list in the Employee Details form. At first it was a simple thing until I think it through what I need to put there.
1. Can I trigger to open Employee Details form from Employee list & define a data to pass to Employee Details form, so that the current event procedure can determine what to do? If I can, how to do it?2. How to alert user to save when user's trying to navigate away from current record?3. Did I think it in a complicated way?RyanOn Mon, Feb 10, 2014 at 8:14 PM, John Viescas <JohnV@msn.com> wrote:
Ryan-The other form will have to set the locked / unlocked. What is it you're trying to do?John Viescas, AuthorMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access ApplicationsSQL Queries for Mere Mortals(Paris, France)
On Feb 10, 2014, at 2:04 PM, 易健福 <ryan.paschal@gmail.com> wrote:What if it allows to edit only when triggered from another form? Let's say Employees List form.How the Employee Detail form determine where it was triggered from? Will Tag property do the job?On Mon, Feb 10, 2014 at 7:58 PM, 易健福 <ryan.paschal@gmail.com> wrote:
John,There's one more thing I forgot to mention.How to code a combo box that lists the employees' name & jump to the related record after I select one name?Thanks.Regards,RyanOn Mon, Feb 10, 2014 at 7:55 PM, 易健福 <ryan.paschal@gmail.com> wrote:
Dear John,I don't understand the Tag property.
What is that? How does it work?RyanOn Mon, Feb 10, 2014 at 5:03 PM, John Viescas <JohnV@msn.com> wrote:
Ryan-Yes, you can do that. My code simply locks/unlocks all text boxes, combo boxes, subforms, and command buttons it finds in the Detail section.All controls have a Tag property that you can set to whatever you like. I've seen some versions of lock/unlock code that examines the Tag property to decide whether to change the control or not. You can put something like "lock" in the Tag property of the controls you want affected and then look for that value in your loop that looks at all controls.John Viescas, AuthorMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access ApplicationsSQL Queries for Mere Mortals(Paris, France)
On Feb 10, 2014, at 10:50 AM, 易健福 <ryan.paschal@gmail.com> wrote:John,What do you think if I combine it with putting the 'locked=false' property in some controls in the current event? So, that some controls will remain active every time move to the current record.RyanOn Mon, Feb 10, 2014 at 4:33 PM, John Viescas <JohnV@msn.com> wrote:
Ryan-When you set AllowEdits to False, *all* of your controls become locked. If, for example, you have an unbound combo box in the form header to help search for records, the user won't be able to select a value in the combo. Note that my code locks the controls only in the Detail section of the form. It therefore leaves any combo boxes, text boxes, or command buttons still enabled in the form header or footer.John Viescas, AuthorMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access ApplicationsSQL Queries for Mere Mortals(Paris, France)
On Feb 10, 2014, at 10:28 AM, 易健福 <ryan.paschal@gmail.com> wrote:Dear John,After reviewing your codes, what do you think if I use allowedits property to false instead of locking each controls?
Is there other implications & side effect?RyanOn Mon, Feb 10, 2014 at 4:13 PM, 易健福 <ryan.paschal@gmail.com> wrote:
Thank you for your answer.Let me digest the codes first.RyanOn Sat, Feb 8, 2014 at 5:01 PM, John Viescas <JohnV@msn.com> wrote:
Ryan-The default design of a form in Access lets you easily edit and save data with absolutely no code. However, it's easy to modify this default behavior if you're willing to write a bit of code.First, to deal with allowing / disallowing edits, you need a little procedure to lock / unlock all editable controls - something like this:Private Sub Lockit(intLocked As Integer)Dim ctl As ControlOn Error Resume Next' Move the focus to a control that won't be affectedMe.cmdSave.SetFocus' Set Locked for all text boxes, combo boxes, check boxes, and subforms' in Detail section based on paramterFor Each ctl In Me.Section(0).ControlsSelect Case ctl.ControlTypeCase acTextBox, acComboBox, acSubformctl.Locked = intLockedCase acCommandButtonctl.Enabled = Not (intLocked)End SelectNext ctlEnd SubUse the Current event of the form to control initial locking:Private Sub Form_Current()' If on a new record,If Me.NewRecord Then' Unlock all controlsLockit FalseElse' Prevent editing of an existing recordLockit TrueEnd IfEnd SubCreate a command button that has a caption of "Edit Record" called cmdEdit and add this code:Private Sub cmdEdit_Click()' User wants to edit - unlock everythingLockit FalseEnd SubCreate another command button to force a save called cmdSave:Private Sub cmdSave_Click()' If changes have been madeIf Me.Dirty Then' Force a saveMe.Dirty = False' .. and lock all controlsLockit TrueEnd IfEnd SubIf a user wants to clear all edits without saving, provide a "Cancel" button called cmdCancel with code like this:Private Sub cmdCancel_Click' If changes have been madeIf Me.Dirty Then' Clear all editsMe.UndoEnd If' Relock all controlsLockit TrueEnd SubAnd finally, to catch and verify all attempts to save, use the form's Before Update event:Private Sub Form_BeforeUpdate(Cancel As Integer)' Ask the user to confirmIf vbNo = MsgBox("Are you sure you want to save your " & _"changes?", vbQuestion + vbYesNo + vbDefaultButton2) Then' User clicked No, so back out changesMe.Undo' And tell Access NOT to saveCancel = TrueEnd IfEnd SubTry it, you'll like it!John Viescas, AuthorMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access ApplicationsSQL Queries for Mere Mortals(Paris, France)
On Feb 8, 2014, at 6:50 AM, Ryan S. <ryan.paschal@gmail.com> wrote:Hi,I am MS Access 2007's user. I hope experts here can help me with my problems. My problems perhaps too simple for experts here.
Here is my case:I need a form to add/edit employee data.
I have made the basic form using form wizard, but it saves everything into table anyway without confirmation because it's connected to employee table directly via RecordSource.
I want the form to:
- Have a button for saving the record; confirms whether or not user want to save the record
- Have cancel button to cancel all data entry & clean the form to start over
- In view mode, be uneditable unless clicked the edit button
Please help me.
Thank you in advance.Best regards,Ryan
__._,_.___
| Reply via web post | Reply to sender | Reply to group | Start a New Topic | Messages in this topic (17) |
.
__,_._,___
Tidak ada komentar:
Posting Komentar