Kind of a Newbie here so I hope my question isn’t too ignorant. I have created a text box for a date entry that uses an “On Got Focus” Machro to obtain the current time. Works great, except that it will, of course, change the time each time it is tabbed over by the operator. Is there a way to (perhaps with a “On Exit” or “On Lost Focus” machro) that I can “lock” the text box after the initial entry? There is NEVER a need to edit this entry once the original time has been determined. Thanks.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
‘Lock-on-exit’ text box? (2002)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » ‘Lock-on-exit’ text box? (2002)
- This topic has 14 replies, 4 voices, and was last updated 22 years, 8 months ago.
AuthorTopicWSbfxtrfcmgr
AskWoody LoungerAugust 14, 2002 at 10:54 pm #375012Viewing 0 reply threadsAuthorReplies-
Weyrman
AskWoody LoungerAugust 15, 2002 at 1:20 am #608577If you are logging the time that the record was created, set the default value for the field in the table to Now() and lock the textbox on the form permanently. This way, the time will be auto stamped when the record is created, can be viewed at any time but cannot be altered.
If this does what you want, there is no need for the code in the On got focus event.
Hope this helps
-
WSbfxtrfcmgr
AskWoody LoungerAugust 15, 2002 at 1:46 am #608581Thanks for your input Allen – much appreciated. That is the way I had it originally set up, but we found that the operators almost always completed an order and opened a new form. With the default of Now() the time they OPENED the form was entered into the time field, rather than the time they actually took the order. It can be several minutes (even hours at times) before they take another order. This makes the order entry “time” inaccurate. That was my reasoning in using the “On Got Focus” event to trigger the time entry – even though the form was open, an entry would not occur until they started taking the order. Any other thoughts?
-
Weyrman
AskWoody LoungerAugust 15, 2002 at 2:47 am #608592OK I will assume that you have a form that is used for order entry as well as viewing or edting existing orders, and that the time text box is bound to JobTime.
When the order form is closed or moved to a new order, the ‘Update” event happens, which writes any changes back to the table. When a new order is entered, the form is in ‘DataEntry’ mode.
If you put the following code in the form’s before update event, then it will write the time that the order was finished and/or the form was closed.
Private Sub Form_BeforeUpdate()
if me.DataEntry = true then [JobTime] = Now()
End Sub
This says, if the order is a new one, then when you close, set the value of [Jobtime] to Now().
The DataEntry check will stop the value being changed if the order is edited later for some reason. As with my earlier suggestion, set the time textbox to locked so that the value can be seen later but not edited.
I hope this helps (and is right! I’ve only just started offering suggestions)
-
WSbfxtrfcmgr
AskWoody LoungerAugust 15, 2002 at 3:34 am #608594Woah! That was pretty scary! I got some kind of screen flash and the application closed.
I re-started and went back and deleted the entry from design view. This is what was entered:Private Sub Form_BeforeUpdate()
If Me.DataEntry = True Then [Order Time] = Now()
End SubI really don’t have any experiance with VB so maybe the above entry has an error in it. Whatever, the app crashed when I ran it. All is back to the way it was before, but of course I still have the issue. Need food – sleep. Maybe a clear head in the morning will help. Very much appreciate your assist – if you have any other ideas (or can show me where I went wrong in entering the code) I’d very much appreciate it.
-
Weyrman
AskWoody LoungerAugust 15, 2002 at 4:07 am #608599Humblest Apologies, I should have tried it out before offering the idea. I was on the right track though. The following has been tested (Acc 97):
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull([Order Time]) Then [Order Time] = Now()
End SubBefore the record is updated, the Time field is checked for a value. If nothing is there, (A new order), the date/time is written in. If the field has a value, then the record exists and has been edited, so the step is bypassed.
This also assumes that the field in the table is set to Date/Time Data type and that when you look at your form in design mode, Order Time is written in the text box.
I don’t know why your screen crashed. If the above crashes also, maybe there are coding differences between 97 and 2002 (Drool) and I would suggest that you ask for someone with 2002 to check it for you.
-
WSbfxtrfcmgr
AskWoody LoungerAugust 15, 2002 at 1:17 pm #608675Well, I’m thinking I just don’t have enough knowledge to deal with this issue, or perhaps even the ability to follow directions. I copied your code to VB and ran it. This is what I got in the ‘Visual Basic Error Message’:
Run-time error ‘2465’:
Can’t find the field “|” referred to in your expressionI went back and looked at the expression and there is no “|” anywhere in it. I’m beginning to feel like Homer Simpson (can’t find the “any” key).
Anyway, I guess I’m back to square one. I do thank you for your help so far and offer my apologies for whatever I’m doing wrong at this point. It must be equally frustrating for you.
-
WSmrabrams
AskWoody LoungerAugust 15, 2002 at 1:49 pm #608686Sorry to jump in like this, but I know how frustrating this gets.
It looks as though you may have used the wrong key.
If IsNull([Order Time]) Then [Order Time] = Now()The bolded brackets are the key to the right of the letter P on the keyboard.
If this doesn’t help, I do apologize for butting in!!
Like I said, this can get frustrating, but once you get it working, it’ll be worth it !!
Good Luck!!
Michael
-
WSbfxtrfcmgr
AskWoody Lounger -
WBell
AskWoody_MVPAugust 15, 2002 at 1:58 pm #608691I think things have gotten off track here – I believe you are adding a new record with the form. If that’s the case, you want to use the Before Insert event to set the field value. In that case you simply set the code with no If statement or anything. We do this regularly with both a time stamp, and the userid of the person who entered the record. We also regularly log who last changed a record with similar code in the Before Update event. There is another alternative to this, and that is to set a default value in the table itself. You can simply set the default value for the field in the table to Now() and all new records will receive that value unless someone actually puts in a different value. And the lock on the form control Alan suggests is appropriate – you might also want to make it not enabled as well so users can’t even tab into it or click into it. Hope this gets things restarted.
-
WSbfxtrfcmgr
AskWoody LoungerAugust 15, 2002 at 2:50 pm #608717I just KNEW I should have been dropping breadcrumbs along the way!! I’m totally lost now.
I actually have three forms originating from the same query (calculated fields) which is based on a single table. They are:
1. Order Entry (which displays a single new order – data entry only – with ‘Order Time’ locked)
2. Order Detail (which displays a single order selected from a dispatch screen (form) – editable – with ‘Order Time’ unlocked)
3. Order History (which displays all orders – editable – with ‘Order Time’ unlocked)I now realize that ‘Order Time’ should probably be locked on all screens if I can get the time entry issue corrected. As I mentioned in one of my earlier posts, I did have the default set to Now() in the Table, but it entered a time at the moment the form was “opened”, rather than the time the operator began to actually enter an order. Geesh, I think I’m getting dizzy!
Now I’m not sure if I’m supposed to be entering conditions or values in the field, or the form. When you say to use the Before Insert event, do you mean in the field or the form? You say to set the code with no If statement or anything. How to I set a code for this event if I don’t make any entry? It’s 8:48 here – too early to start drinking?
Also, if you would be so kind, please see my other post on VB books – any input would be greatly appreciated!
Bryan (I think)
-
WBell
AskWoody_MVPAugust 15, 2002 at 6:41 pm #608785Sorry – I should have been a bit more explicit. I was thinking of the behavior of SQL Server, where the time is set at the time the table is saved, so if you need exact time, the answer is to use the Before Insert event of the form, and put a simple line of code in the event procedure that says
me![Timestamp] = Now
where the me![Timestamp] expression refers to the control that displays the field. This will cause the field to be set before each record is saved. If you are using Access security, you can use a similar expression “me![WhoEntered] = CurrentUser()” to capture the identity of the user who created the new record. (If you don’t have security active, it will always say “Admin” as that user is how everyone run Access in that situation.) Hope this clarifies things some – but bear up as it is now time for lunch soon and you could slip out to the local bar.
-
WSbfxtrfcmgr
AskWoody LoungerAugust 15, 2002 at 7:39 pm #608795Praise the Lord and pass the tequila – we got a winner!!
This works great! I locked the field in the history and detail views, as well as the new order entry form. Now the order entry form opens without the time, the operator can spend all day staring at the screen if they want, but the time won’t be captured until they have completed the form. As the only other time the form is visible is when they look at the history or detail view (where the cell is locked), the time can never be changed.
I’m going to have to lump you in with the United Way my friend – “I don’t know you, but I love you”. Thank you so much for your help on this and for your advise on the VB self-teach issue. Your selfless response to a desperate amatuer is most worthy of high praise. If ever I should get to the point of actually having some value as a contibutor, I shall not forget my debt.
Gratefully,
Bryan -
Weyrman
AskWoody Lounger -
WSbfxtrfcmgr
AskWoody LoungerAugust 15, 2002 at 9:11 pm #608821No worries mate! If you’re ever in the states let me know, I’ve got a cool Fosters for ya!
Seriously, every suggestion is welcomed and a valued learning tool. At this point in my venture down Access Madness Lane I appreciate every effort by those who are willing. No apology wanted, requred, or even appropriate.
Bryan
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
HP Pavilion Will Not Wake Up After Being Idle for Longer Period
by
WSwalterwood44
3 hours, 11 minutes ago -
Make a Windows 11 Local Account Passwordless
by
Drcard:))
2 hours, 45 minutes ago -
Ubuntu 25.04 (Plucky Puffin)
by
Alex5723
6 hours, 21 minutes ago -
24H2 fixed??
by
CWBillow
9 hours, 2 minutes ago -
Uninstalr Updates
by
jv16
11 hours, 30 minutes ago -
Apple zero days for April
by
Susan Bradley
16 hours, 54 minutes ago -
CVE program gets last-minute funding from CISA – and maybe a new home
by
Nibbled To Death By Ducks
22 hours, 25 minutes ago -
Whistleblower describes DOGE IT dept rumpus at America’s labor watchdog
by
Nibbled To Death By Ducks
1 day, 10 hours ago -
Seeing BSOD’s on 24H2?
by
Susan Bradley
17 hours, 9 minutes ago -
TUT For Private Llama LLM, Local Installation and Isolated from the Internet.
by
bbearren
1 day ago -
Upgrade from Windows 10 to 11
by
Holdsworth8
1 day, 18 hours ago -
Microsoft : AI-powered deception: Emerging fraud threats and countermeasures
by
Alex5723
1 day, 21 hours ago -
0patch
by
WSjcgc50
22 hours, 43 minutes ago -
Devices might encounter blue screen exception with the recent Windows updates
by
Susan Bradley
1 day, 15 hours ago -
Windows 11 Insider Preview Build 22631.5261 (23H2) released to Release Preview
by
joep517
2 days ago -
Problem opening image attachments
by
RobertG
2 days, 2 hours ago -
advice for setting up a new windows computer
by
routtco1001
2 days, 17 hours ago -
It’s Identity Theft Day!
by
Susan Bradley
1 day, 21 hours ago -
Android 15 require minimum 32GB of storage
by
Alex5723
2 days, 21 hours ago -
Mac Mini 2018, iPhone 6s 2015 Are Now Vintage
by
Alex5723
2 days, 22 hours ago -
Hertz says hackers stole customer credit card and driver’s license data
by
Alex5723
2 days, 22 hours ago -
Firefox became sluggish
by
Rick Corbett
14 hours, 51 minutes ago -
Windows 10 Build 19045.5794 (22H2) to Release Preview Channel
by
joep517
3 days, 2 hours ago -
Windows 11 Insider Preview Build 22635.5235 (23H2) released to BETA
by
joep517
3 days, 3 hours ago -
A Funny Thing Happened on the Way to the Forum
by
bbearren
2 days ago -
Download speeds only 0.3Mbps after 24H2 upgrade on WiFi and Ethernet
by
John
5 hours, 17 minutes ago -
T-Mobile 5G Wireless Internet
by
WSmmi16
2 days ago -
Clock missing above calendar in Windows 10
by
WSCape Sand
2 hours, 16 minutes ago -
Formula to Calculate Q1, Q2, Q3, or Q4 of the Year?
by
WSJon5
3 days, 17 hours ago -
The time has come for AI-generated art
by
Catherine Barrett
2 days, 21 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.