If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Do not overwrite a field
I have a form where users click a button and it inputs the current time
in a field called TimeStart to indicate that they have started working on a job. I have found where users inadvertently (I assume) go back and hit that button again and it overwrites the field with the then current time. How can I prevent that from happening? In other words, when the user clicks the button, if the field already has a value in it, I do not want it to overwrite what's already in there. Also, I would like to give a message to the user stating that "You have already started working on this job" if that happens (obviously, I don't want that message to appear under normal circumstances, i.e., if the field is blank when they click the button). Thanks for any help, Darrell |
#2
|
|||
|
|||
Do not overwrite a field
hi Darrell,
On 17.03.2010 15:45, Darrell Childress wrote: I have a form where users click a button and it inputs the current time in a field called TimeStart to indicate that they have started working on a job. I have found where users inadvertently (I assume) go back and hit that button again and it overwrites the field with the then current time. How can I prevent that from happening? The field should be a Date/Time field with required set to no and no default value. Use this condition for testing: If IsNull(Me![TimeStart]) Then Me![TimeStart] = Now() Else MsgBox "Already started." End If mfG -- stefan -- |
#3
|
|||
|
|||
Do not overwrite a field
In the click event of your button put something like this
If Nz([TimeStart],"") = "" then [TimeStart] = Format(Now(),"Short Time") Else Msgbox "You have already started working on this job" End If "Darrell Childress" wrote: I have a form where users click a button and it inputs the current time in a field called TimeStart to indicate that they have started working on a job. I have found where users inadvertently (I assume) go back and hit that button again and it overwrites the field with the then current time. How can I prevent that from happening? In other words, when the user clicks the button, if the field already has a value in it, I do not want it to overwrite what's already in there. Also, I would like to give a message to the user stating that "You have already started working on this job" if that happens (obviously, I don't want that message to appear under normal circumstances, i.e., if the field is blank when they click the button). Thanks for any help, Darrell . |
#4
|
|||
|
|||
Do not overwrite a field
That works great. One more question. Previously, I had all the steps
being done in a macro, so when the button was clicked, it actually called up a macro, with the first step in the macro being to enter the current time. I removed that step from the macro and used the code below. I would also like it to NOT even call up the macro if there is already a value in the TimeStart field. In other words, if the TimeStart field is blank, then run all the code. If the TimeStart already contains a value, then only display the "Already started" message and quit. Here's my current code: Private Sub StartJob_Click() If IsNull(Me![TimeStart]) Then Me![TimeStart] = Now() Else MsgBox "This job has already been started" End If Dim stDocName As String stDocName = "mcrStartJob_Laser_SOD" DoCmd.RunMacro stDocName End Sub If necessary, I think I could completely remove the macro commands and just write the necessary VBA code to do what the macro is doing. Would that be the better way to go anyway? On 3/17/10 11:32 AM, Stefan Hoffmann wrote: hi Darrell, On 17.03.2010 15:45, Darrell Childress wrote: I have a form where users click a button and it inputs the current time in a field called TimeStart to indicate that they have started working on a job. I have found where users inadvertently (I assume) go back and hit that button again and it overwrites the field with the then current time. How can I prevent that from happening? The field should be a Date/Time field with required set to no and no default value. Use this condition for testing: If IsNull(Me![TimeStart]) Then Me![TimeStart] = Now() Else MsgBox "Already started." End If mfG -- stefan -- |
#5
|
|||
|
|||
Do not overwrite a field
As an alternate approach, what about making it impossible?
If you disable that button when there's already a date/time value in the field, no one has to get the message "Dummy! You already have a date/time started!" Combine this with the other suggestion you got to pre-load the date/time using DefaultValue, and your user wouldn't even have to click a button! Good luck Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "Darrell Childress" wrote in message ... I have a form where users click a button and it inputs the current time in a field called TimeStart to indicate that they have started working on a job. I have found where users inadvertently (I assume) go back and hit that button again and it overwrites the field with the then current time. How can I prevent that from happening? In other words, when the user clicks the button, if the field already has a value in it, I do not want it to overwrite what's already in there. Also, I would like to give a message to the user stating that "You have already started working on this job" if that happens (obviously, I don't want that message to appear under normal circumstances, i.e., if the field is blank when they click the button). Thanks for any help, Darrell |
#6
|
|||
|
|||
Do not overwrite a field
Excellent idea Jeff, and I like your reasoning. Thanks,
Darrell On 3/17/10 3:11 PM, Jeff Boyce wrote: As an alternate approach, what about making it impossible? If you disable that button when there's already a date/time value in the field, no one has to get the message "Dummy! You already have a date/time started!" Combine this with the other suggestion you got to pre-load the date/time using DefaultValue, and your user wouldn't even have to click a button! Good luck Regards Jeff Boyce Microsoft Access MVP |
#7
|
|||
|
|||
Do not overwrite a field
hi Darell,
On 17.03.2010 19:42, Darrell Childress wrote: I removed that step from the macro and used the code below. I would also like it to NOT even call up the macro if there is already a value in the TimeStart field. In other words, if the TimeStart field is blank, then run all the code. If the TimeStart already contains a value, then only display the "Already started" message and quit. Just place the call to the macro into the correct If branch: Private Sub StartJob_Click() On Local Error GoTo LocalError If IsNull(Me![TimeStart]) Then Me![TimeStart] = Now() Me.Dirty = False ' Save the record. DoCmd.RunMacro "mcrStartJob_Laser_SOD" Else MsgBox "This job has already been started" End If Exit Sub LocalError: MsgBox "Error while running job." & vbCrLf & _ "Description: " & Err.Description, vbCritical End Sub If necessary, I think I could completely remove the macro commands and just write the necessary VBA code to do what the macro is doing. Would that be the better way to go anyway? I would say yes, cause you have more control, more possibilities and if you're used to it the ability to faster read and write VBA macros. But it's not necessary, nor mandatory. mfG -- stefan -- |
#8
|
|||
|
|||
Do not overwrite a field
Thanks for the help on this, it's working great, plus I learned something.
On 3/18/10 4:54 AM, Stefan Hoffmann wrote: hi Darell, On 17.03.2010 19:42, Darrell Childress wrote: I removed that step from the macro and used the code below. I would also like it to NOT even call up the macro if there is already a value in the TimeStart field. In other words, if the TimeStart field is blank, then run all the code. If the TimeStart already contains a value, then only display the "Already started" message and quit. Just place the call to the macro into the correct If branch: Private Sub StartJob_Click() On Local Error GoTo LocalError If IsNull(Me![TimeStart]) Then Me![TimeStart] = Now() Me.Dirty = False ' Save the record. DoCmd.RunMacro "mcrStartJob_Laser_SOD" Else MsgBox "This job has already been started" End If Exit Sub LocalError: MsgBox "Error while running job." & vbCrLf & _ "Description: " & Err.Description, vbCritical End Sub If necessary, I think I could completely remove the macro commands and just write the necessary VBA code to do what the macro is doing. Would that be the better way to go anyway? I would say yes, cause you have more control, more possibilities and if you're used to it the ability to faster read and write VBA macros. But it's not necessary, nor mandatory. mfG -- stefan -- |
Thread Tools | |
Display Modes | |
|
|