RE: KeyDown Escape Key not working
- From: Tom Wickerath <AOS168b AT comcast DOT net>
- Date: Mon, 29 Jun 2009 21:16:01 -0700
Hi Tina,
Except, there is that lesson about OpenArgs that I could use .... It's
buried in the original post.
From your original post:
Finally, I have additional code that pushes a value to the form when it
loads. I don't know how to do OpenArgs because I don't understand it, but
the code I have works for me. I don't mind a lesson if you have time.
Here's the code that should probably be OpenArgs:
Private Sub Form_Load()
Forms!frmQuickAdd_TDM!Family_ID = Forms!frmQuickAdd_TDM!
FamilyIdFromForm
End Sub
It looks to me like your code is pulling its value from the previous form,
rather than pushing it.
The optional OpenArgs parameter of the DoCmd.OpenForm Method allows one to
pass a string value to a form that is being opened. The form being opened can
read this value, using code in the Form_Open event procedure. You can see an
example in the sample Northwind database, in the Sub AddProducts_Click()
procedure, found in the Suppliers form:
DoCmd.OpenForm strDocName, , , , acAdd, , Me!SupplierID
The above example uses positional arguments (arguments that MUST be
separated by the correct number of commas), which I think is a good way to
make one's VBA code difficult to read. I recommend using named arguments
instead. Yes, it takes a bit more time to write code using named arguments,
but I think you will agree that the result is much more readable. The line
above can be re-written as this, which also allows you to eliminate the
declaration and assignment of the strDocName variable:
DoCmd.OpenForm "Products", DataMode:=acAdd, OpenArgs:=Me!SupplierID
The named argument is separated from the value using a ":=".
Okay, so now the Products form opens, and you can see how this value is used
in the Private Sub ProductName_AfterUpdate() procedure, to assign the
SupplierID value to the field that serves as the control source for the
Supplier combo box:
Private Sub ProductName_AfterUpdate()
' If OpenArgs property isn't null, set SupplierID to value of form's OpenArgs
' property. OpenArgs will have a value if Products form is opened by clicking
' AddProducts command button on Suppliers form.
If IsNull(Forms!Products.OpenArgs) Then
Exit Sub
Else
Me!SupplierID = Forms!Products.OpenArgs
End If
End Sub
Hope this helps some.
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
"Tina Hudson" wrote:
Okay. This one was easy and I figured it out. I didn't have Key Preview set
to Yes.
I just wanted to save you time answering my post when I figured it out.
Except, there is that lesson about OpenArgs that I could use .... It's
buried in the original post.
--
Thanks,
Tina Hudson
__________________________________________
"Tina Hudson" wrote:
I have the following code on the On Key Down event but it doesn't work on a
particular form. It works for all other forms that have it. The form which
it doesn't work on has a cbo field as the first field, but even if I skip
over that and enter a date in the next field, the code doesn't work.
Here's the code to disable the escape key:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'This will turn the escape key off
If KeyCode = vbKeyEscape Then
KeyCode = 0
End If
End Sub
I also have code to add my own error message if the first field (the cbo
box) doesn't have data in it. Could this be messing everything up?
Here's the code to show my own error message:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 3314
MsgBox "You must enter whether TDM was held before you can save the
record."
Response = acDataErrContinue
Case Else
Response = acDataErrDisplay
End Select
End Sub
Finally, I have additional code that pushes a value to the form when it
loads. I don't know how to do OpenArgs because I don't understand it, but
the code I have works for me. I don't mind a lesson if you have time.
I don't see anything else that I have in the coding behind the form that
might interfere with the KeyDown event.
Here's the code that should probably be OpenArgs:
Private Sub Form_Load()
Forms!frmQuickAdd_TDM!Family_ID = Forms!frmQuickAdd_TDM!FamilyIdFromForm
End Sub
Thanks,
Tina Hudson
-----------------------------------------------------------------------------
Less Spam Better enjoyable experience
Visit : news://spacesst.com
.
- References:
- KeyDown Escape Key not working
- From: Tina Hudson
- RE: KeyDown Escape Key not working
- From: Tina Hudson
- KeyDown Escape Key not working
- Prev by Date: Re: ComboBox to update TextBoxes on Form
- Next by Date: 2003 Database won't compile
- Previous by thread: RE: KeyDown Escape Key not working
- Next by thread: Link criteria on Open Form Command Button
- Index(es):