Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 02-24-2018, 06:11 PM   #1
helmerr
Newly Registered User
 
Join Date: Nov 2013
Posts: 140
Thanks: 33
Thanked 0 Times in 0 Posts
helmerr is on a distinguished road
Form controls not updating unless click outside control

I figure there may be an easy solution for this one:

I'm trying to add new records using a form with text and combo boxes. On the form's On_Load event, I using the command DoCmd.GoToRecord , , acNewRec to prepare for new record entry first, thus clearing the controls.

Data is entered into the controls, then the user clicks the cmdSave button which initiates the code below. However, unless the user clicks elsewhere after filling in the last text box control, etc., the form does not recognize that data was actually entered into the final control. The user receives the message from the save code to "Please fill in all required fields."

Code:
'test required fields
If IsNull(Me.txtVehicleID.Value) _
Or IsNull(Me.cboVehicleNum.Value) _
Or IsNull(Me.txtODate.Value) _
Or IsNull(Me.txtFuel.Value) _
Or IsNull(Me.txtOdometer.Value) Then
    MsgBox "Please fill in all required fields."
Else

    MsgBox "Record saved."

    'Requery forms
    Me.Requery
    Me.Parent.frmMileageDetail.Form.Requery

    ' Prepare form for new record input
    DoCmd.GoToRecord , , acNewRec

End If

helmerr is offline   Reply With Quote
Old 02-24-2018, 06:23 PM   #2
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,761
Thanks: 10
Thanked 1,290 Times in 1,227 Posts
MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all
Are you aware the you can put a form in DataEntry mode? Then the behaviors you describe are automatic, and you don't need a save button. Just tab out of the last field and into the next record, which is new by default.
I think that would be a simpler solution that making this work.
hth
Mark
__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
Old 02-24-2018, 06:46 PM   #3
helmerr
Newly Registered User
 
Join Date: Nov 2013
Posts: 140
Thanks: 33
Thanked 0 Times in 0 Posts
helmerr is on a distinguished road
Re: Form controls not updating unless click outside control

Hi Mark,

My form is actually composed of one main form and two subforms. The top subform allows for new entries and edits, and has command buttons for adding a new record, resetting the form as an easy way to start the new record from scratch in case of error, a save button, a delete button, and a report button. The Add and Save buttons are there for the user's visual comfort.

The bottom sub form is a continuous form and if a user selects an item from the bottom sub form, it is populated to the top form for editing. I'm not allowing edits on the continuous form.

At any rate; I did try enabling data entry mode as suggested, but received the same error.

helmerr is offline   Reply With Quote
Old 02-24-2018, 09:35 PM   #4
JHB
Have been here a while
 
Join Date: Jun 2012
Location: In the south of Denmark (Jutland), near the German border.
Posts: 7,720
Thanks: 3
Thanked 2,082 Times in 2,037 Posts
JHB has a spectacular aura about JHB has a spectacular aura about
Re: Form controls not updating unless click outside control

I can't reproduce that error, could you post your database with some sample data + a description how to get that error?
__________________
If the above post has helped you, why not take the time to say thank you, by pressing the "Thumbs up."
JHB is offline   Reply With Quote
The Following User Says Thank You to JHB For This Useful Post:
helmerr (02-25-2018)
Old 02-24-2018, 11:58 PM   #5
isladogs
High Noon Moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 11,370
Thanks: 115
Thanked 3,111 Times in 2,829 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: Form controls not updating unless click outside control

After each field is updated, you could set the focus to another control.
This will cause the change to be committed and should solve your issue
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Colin (Mendip Data Systems)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Common sense and a sense of humour are the same thing, moving at different speeds. (Clive James - RIP)
isladogs is offline   Reply With Quote
The Following User Says Thank You to isladogs For This Useful Post:
helmerr (02-25-2018)
Old 02-25-2018, 07:10 AM   #6
helmerr
Newly Registered User
 
Join Date: Nov 2013
Posts: 140
Thanks: 33
Thanked 0 Times in 0 Posts
helmerr is on a distinguished road
Re: Form controls not updating unless click outside control

Hey guys - I've attached a copy of the database.

Also, I set tried using me.txtVehicleID.SetFocus on the control txtOdometer's After Update event (since this is likely the last control to be typed in), but it didn't help. I haven't tried using it's On Change event, as I'm pretty sure this would move focus to the other control after each typed character.
Attached Files
File Type: accdb Mileage.accdb (864.0 KB, 20 views)
helmerr is offline   Reply With Quote
Old 02-25-2018, 07:25 AM   #7
helmerr
Newly Registered User
 
Join Date: Nov 2013
Posts: 140
Thanks: 33
Thanked 0 Times in 0 Posts
helmerr is on a distinguished road
Re: Form controls not updating unless click outside control

I think I've got it:
I had needed to put the above command "me.txtVehicleID.SetFocus" as the first event in the cmdSave button.

Thanks for your help.

helmerr is offline   Reply With Quote
Old 02-25-2018, 11:33 AM   #8
isladogs
High Noon Moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 11,370
Thanks: 115
Thanked 3,111 Times in 2,829 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: Form controls not updating unless click outside control

Hi

Just got back & had a quick look at this

Quote:
I had needed to put the above command "me.txtVehicleID.SetFocus" as the first event in the cmdSave button.
I don't see how you can do that as the control is hidden

Alternatively, you could also do this instead

Code:
Private Sub txtOdometer_AfterUpdate()
    If Me.Dirty Then Me.Dirty = False
End Sub
Two other suggestions:
1. Add a validation rule (>0 to the Fuel textbox to prevent invalid entries like -5
2. Similarly add a validation rule > previous odometer entry for similar reasons
AND/OR Pre-enter the previous odometer value for editing by the user

The first is easy - the second a bit more tricky
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Colin (Mendip Data Systems)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Common sense and a sense of humour are the same thing, moving at different speeds. (Clive James - RIP)
isladogs is offline   Reply With Quote
Old 02-25-2018, 12:07 PM   #9
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,761
Thanks: 10
Thanked 1,290 Times in 1,227 Posts
MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all
I downloaded your Db, and if I was doing what you are doing in that header form, I would not bind it to a record source at all. I would use it unbound, validate all the data entered in the controls prior to save, and then use an insert query to push the new data directly into the table.

You can do a similar thing if needs be to do updates. Load the unbound data in the subform and save the ID somewhere too, but hidden. If the ID is present, then hitting save is a update, not a insert.

But it doesn't make sense to me to have a bound form, AND a save button, because a bound form is designed to save automatically, so you are always going to have an uphill struggle with that design, IMO. Users will find a way--with a bound form--to save that record in ways that by-pass your save button, like hitting the pagedown key, or clicking in your detail section, and so if you want to have all the control a save button provides, then you have to (in my mind) disable ALL the automatic features of a bound form.

hth
Mark
__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
The Following User Says Thank You to MarkK For This Useful Post:
helmerr (02-25-2018)
Old 02-25-2018, 12:27 PM   #10
helmerr
Newly Registered User
 
Join Date: Nov 2013
Posts: 140
Thanks: 33
Thanked 0 Times in 0 Posts
helmerr is on a distinguished road
Re: Form controls not updating unless click outside control

Hmm.. I never thought of that. Let met think about this again..
helmerr is offline   Reply With Quote
Old 02-25-2018, 11:28 PM   #11
JHB
Have been here a while
 
Join Date: Jun 2012
Location: In the south of Denmark (Jutland), near the German border.
Posts: 7,720
Thanks: 3
Thanked 2,082 Times in 2,037 Posts
JHB has a spectacular aura about JHB has a spectacular aura about
Re: Form controls not updating unless click outside control

The "problem" is that it is not a real button but a picture you are treated as a button, meaning that the focus does not leave the last control you're inputting data.
A solution could be to use a real button where you have the image shown, (if you want to keep your design).
__________________
If the above post has helped you, why not take the time to say thank you, by pressing the "Thumbs up."
JHB is offline   Reply With Quote
The Following User Says Thank You to JHB For This Useful Post:
helmerr (02-26-2018)
Old 02-26-2018, 09:27 AM   #12
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,761
Thanks: 10
Thanked 1,290 Times in 1,227 Posts
MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all
A button also has a Transparent property, so you can put it on top of a picture, and still get all the functionality.
__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
Old 02-26-2018, 10:29 AM   #13
isladogs
High Noon Moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 11,370
Thanks: 115
Thanked 3,111 Times in 2,829 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: Form controls not updating unless click outside control

I had assumed without checking that the OP had done just that.

As you can modify buttons to have any image you like and have both text and images on buttons, I no longer see any point using images instead of buttons.

Indeed when I look at forms which use images acting as buttons as well as other images such as logos, it's not always obvious what to click!

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Colin (Mendip Data Systems)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Common sense and a sense of humour are the same thing, moving at different speeds. (Clive James - RIP)
isladogs is offline   Reply With Quote
Reply

Tags
control , textbox , update

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating multiple tables after updating form control starrcruise Modules & VBA 0 02-28-2012 12:50 PM
Clicking on control fires previous controls on click event chp1775 Forms 3 05-30-2008 04:25 AM
[SOLVED] Updating the Form controls thru VBA & BeforeUpdate Event?? mmarshad Forms 0 11-25-2002 08:09 AM
Updating a control when I click on the another wjoc1 Forms 3 10-17-2002 07:07 PM
Updating Data Between Form Controls kevsim Modules & VBA 2 08-10-2002 03:22 PM




All times are GMT -8. The time now is 03:29 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World