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

Prevent field from reseting when ESC is pressed

Status
Not open for further replies.

EvilCabal

Programmer
Jul 11, 2002
206
CA
Hi all,

I have a form used to add a record to a table. When I open (on the form_load event), I put the right value in the keyfield. This keyfield is disabled because I don't want the user to change it, but if he press escape when he enter the form the field becomes null!?! What can I do to prevent this? Thanx for the help.
 
I would move the code that assigns the key field value to the after update event of the first field the user completes.

This way, even if they hit the escape key, the number will be reassigned after they complete the first field.

Alternatively, if you are using an explicit save operation, put the code there. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Nice idea but for some reason that doesn't work and the DARN application won't even give me an error msg. Here is my code (The keyField value is contained in the openargs) :

Private Sub txt_AfterUpdate
On error goto Err
Keyfield = me.openargs

Err:
msgbox ("Err " & err & " " & error$)

End sub

For some weird reason this code does nothin at all... If I put a Msgbox at the beginning of the Sub it doesn't even pop-up. But if I remove the line "Keyfield = me.openargs" everything comes back to normal... Please give me a hand!
 
First thing that crosses my mind is that the event code is not associated with the event itself.

How did you create the sub? Just type it in or use the properties dialog (select the field, then set an event procedure?

If you just typed it in, it won't run until you set the After Update property to Event Procedure.

I have a similar situation where I pass a key field to a form on open and it works fine. Here's my code:

Private Sub ContFirst_AfterUpdate()

CustID = Me.OpenArgs

End Sub

Check to make sure the dialog is set correctly. Let me know. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
No, the event is associated correctly because as soon as I remove the line that sets the keyfeild, the remaining code execute... This is really weird, event the error handling does not react. I have been doing this kingd of programs for a year and it's the first time I come up with something like this. I won't have access to the program for the week-end but if you have any ideas let me know, i'll work on it monday. Thank you.
 
If my memory serves me correctly, the OpenArgs are only viable during the open event. So set the value of that box during the form_Open event.

Set the Enabled Property to FALSE and the Locked Property to TRUE. This will let you set a value in code, save the value from the buffer to file in the form update, but prevent the user from editing the value.

Jeff Roberts
Analysis, Design, & Implementation
RenaissanceData.com
 
Also, this from the Access help:

This property is available only by using a macro or by using Visual Basic with the OpenForm method of the DoCmd object. This property setting is read-only in all views.

OpenArgs are like a baton pass between two relay runners. There has to be a DoCmd.OpenForm that generates the OpenArgs to be passed and the OpenArgs need to be utilized in the moment when they are viable--they're not a persistent property that can be accessed throughout the form's screen life. Jeff Roberts
Analysis, Design, & Implementation
RenaissanceData.com
 
Thanx Quehay, the text box was already locked and disabled but the user can still erase it by pressing escape, but now that I know that the openargs only work in the openform event, i'll simply assign it content to a public variable. That way eveything should be fine. Thanx for the help guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top