Submitting values to a text box

tanny81

Board Regular
Joined
Mar 2, 2006
Messages
175
Hi All,

1st foray into Access, so go easy on me.

I have some code at the moment which essentially takes the value slected from a datepicker and enters it into a text box which would otherwise be locked (to prevent the users entering garbage data). I have included a copy of the code below, but essentially this is generating an error message when trying to re-lock the text box stating "You can't lock a control while it has unsaved changes".

I know I could get around this by moving the focus elsewhere prior to this line of code running, but I wanted to know if there was another way to achieve this as doing it that way seems like a bit of a fudge?

Code:
    If PickerValueDate > VerDate Then
        MsgBox "Date selected cannot be in the future", vbExclamation, "Input Error"
        dtpFrom.Enabled = False
        txtDateFrom = ""
        Exit Sub
    Else
    ' Transfer date from date picker to text box
        txtDateFrom.Locked = False
        strDate = Format(dtpFrom, "dd/mm/yyyy")
        txtDateFrom = strDate
        txtDateFrom.Locked = True
        dtpFrom.Enabled = False
    End If
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
tanny,

Why not use the built in validation Rule and text properties to validate the entry? Simply set the validation rule of the textbox to
Code:
< D ate ()
and then imput a message that says "Value cannot be in the future." If they try to set it to tomorrow, they will not be ablr to tab off of the box until they set it correctly.

You can even do
Code:
< D ate ()+1
if today can be included.

EDIT: Why is my code not showing? Leave the spaces out, apparently this board filters that code out.
 
Last edited:
Upvote 0
Wouldn't setting Enabled to False be enough?
 
Upvote 0
You don't need to enable or even unlock the text box to set it with code. So, just remove that part.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,280
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top