A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Do not overwrite a field



 
 
Thread Tools Display Modes
  #1  
Old March 17th, 2010, 02:45 PM posted to microsoft.public.access.forms
Darrell Childress[_3_]
external usenet poster
 
Posts: 32
Default 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  
Old March 17th, 2010, 03:32 PM posted to microsoft.public.access.forms
Stefan Hoffmann
external usenet poster
 
Posts: 991
Default 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  
Old March 17th, 2010, 04:01 PM posted to microsoft.public.access.forms
RonaldoOneNil
external usenet poster
 
Posts: 345
Default 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  
Old March 17th, 2010, 06:42 PM posted to microsoft.public.access.forms
Darrell Childress[_3_]
external usenet poster
 
Posts: 32
Default 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  
Old March 17th, 2010, 07:11 PM posted to microsoft.public.access.forms
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default 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  
Old March 17th, 2010, 07:46 PM posted to microsoft.public.access.forms
Darrell Childress[_3_]
external usenet poster
 
Posts: 32
Default 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  
Old March 18th, 2010, 08:54 AM posted to microsoft.public.access.forms
Stefan Hoffmann
external usenet poster
 
Posts: 991
Default 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  
Old March 18th, 2010, 02:27 PM posted to microsoft.public.access.forms
Darrell Childress[_3_]
external usenet poster
 
Posts: 32
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:48 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.