Disable Deletion/Not allow Deletion

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a field called NewBid and I do not want users to delete the
information from this field. I set the Allow Delete on the form property to
No but it still allows deletions. Surely, there must be a way to accomplish
this or am I going about this wrong?

Thanks!!
 
Well, I want them to be able to add and edit but not delete. When they do, it
deletes another field that is tied to it. In otherwords, I have a
CurrentPrice field and NewBid field. When a new bid is placed it updates the
current price field. so $8.00 is entered in new bid, current price will show
$8.00. If new bid is change $15.00 then current price is $23.00. It works
great except, if someone deletes the information in the NewBid field it also
takes out the CurrentPrice field as well. The code I used was:

Private Sub NewBid_AfterUpdate()
Me.CurrentPrice = Me.CurrentPrice + Me.NewBid
End Sub

If there is another way, I would be most gratful as this is the las thing I
need to fix.

Thanks!!!
 
Stockwell43,

Ok, I thing I finally got it. I'm just at little dense to day (some would
say "every day") . :>)

I can see how the Locked property would not do what you want. Sorry.

Try some code in the On_Exit event of the NewBid textbox to check the value
of the NewBid textbox. I would assume that this field is a number/currency
value so you would most likely check to see that the value of the textbox
would be greater than zero and if not display a message to the user telling
them what the problem is and then place them right back in the textbox.

Something like (just air code):

If Me.NewBid <= 0 then
Me.NewBid.SetFocus
End If

This should put the cursor right back in the NewBid text box until they
enter something greater than zero. Now, you might expect something greater
than some other value. You'll just have to decide just what to check for.

At least this way you do not let them leave without providing a value.
 
Hi Mr. B,

Thank you for your quick response.

I tried the code and nothing happened. When I hit the Delete key, it took
out the dollar amount and then I hit the tab key and it let me leave with no
message. Once I leave, then the Current price field goes blank. Is there a
way to disable the delete key so when the user hits it nothing happens?

You are correct on your assumptions. My fields are number and Currency and I
do NOT want the user to enter a negatice value. Again, it seems to work fine
if you tab to the field and enter a dollar amount but, if you make a mistake
(which I know would happen) most people hit the delete key and start again.
That's when it messes up. I am trying to create this database just so the
department can have some fun with their fund raising whether it be for us
internally or an organization they want to donate to.

If you have a solution to this one last problem, I would be personally
grateful. I tried search the internet for a database already created that
might serve the purpose but couldn't find anything.
 
I knew in reason that there would need to be some additional thing to be done
and checked. That why I indicated that it was "air code". :>)

Here is some code that should do exactly what you want. Use it in the Exit
event of your control. The code below is the entire Exit event from my
control named "txtNewBid". You will only need the code after the Private Sub
line to just befor the End Sub line.

Private Sub txtNewBid_Exit(Cancel As Integer)
'use code from here
Cancel = True
MsgBox "Value is required!", vbOKOnly
Me.txtNewBid.SetFocus
If Me.txtNewBid <= 0 Then
Me.txtNewBid = Null
End If
'end of code needed
End Sub
 
Thanks for the code. When I placed it in the On Exit Event, I put in $8.00
and then the message popped up and wouldn't let me leave the field. So it's
almost there, I just need it to do that if I delete the data rather than
entering the data. I took the code from the word Cancel and copied all the
way down to and including End If. Was that correct? Would it make a
difference if I change my field from NewBid to txtNewBid maybe? Sorry to be a
pain with this and very much appreciate you stay with me on it.
 
Boy, do I have egg on my face. When I copied the code, I missed the initial
IF statement. Well here is the code that should be correct.

If IsNull(Me.txtCurPrice <= 0) Or Me.txtCurPrice <= 0 Then
Cancel = True
MsgBox "Value is required!", vbOKOnly
Me.txtNewBid.SetFocus
If Me.txtNewBid <= 0 Then
Me.txtNewBid = Null
End If
End If

Sorry bout that.
 
Not a problem Mr. B, your still Aces with me just for your patience. The code
does work properly however, is there a way to make the message pop up once
the user hits the Delete Key? Right now when I keydown, it clears the field
and when you try to tab out the message pops up which is great but the
current price field goes blank. So basically, once the data from the NewBid
field disappears, it automatically wipes out the Current price field. If the
information stay in the NewBid field both fields will work as they should. Of
course, my reason for going through all this is because I know someone will
eventually hit the delete key and create this problem so I have to safeguard
against it before going into production.
 
Well, let's give this a try:

First, make sure that at the top of the module for your form you and
included the "Option Explicit" statement.

Declare a variant type variable just below the "Option Explicit" statement:

Dim varCurVal

Next, place the following statement in the Enter event of your NewBid control:

varCurVal = Me.txtNewBid

Replace the current code in the "Exit" event with the code below :

If IsNull(Me.txtNewBid <= 0) Or Me.txtNewBid <= 0 Then
Cancel = True
MsgBox "Value is required!", vbOKOnly
Me.txtNewBid.SetFocus
If Me.txtNewBid <= 0 Then
Me.txtNewBid = Null
End If
If varCurVal > 0 Then 'there was a value in this control
Me.txtNewBid = varCurVal
End If
End If
 
Almost there. When I delete and leave the field, both fields are empty and
the message pops up. When I click OK on the message box the amount in the
NewBid field returns but the CurrentValue amount is still blank.
 
Because I do not know what you are using to populate the CurrentValue field.

So, my suggestion is that you repeat what ever is populating the
CurrentValue field in the code just below the "Me.txtNewBid = varCurVal"
statement. That should replace the value in the CurrentValue field.
 
This what I am using to populate the CurrentValue field.

Private Sub NewBid_AfterUpdate()
Me.CurrentPrice = Me.CurrentPrice + Me.NewBid
End Sub

So I should place this piece of code where you told me and I should be good?

Thank you Mr. B!
 
I guess I am somewhat confused by the code. With that code you are simply
adding the new value entered into the NewBid text box to whatever is already
in the CurrentValue box.

How does the CurrentValue get populated to begin with?

If there is nothing else that populates the CurrentValue box then you can
regroup and just put an if statement around the current statement in the
After Update event.

Something like:

If not isnull(me.NewBid) and me.NewBid > 0 then
Me.CurrentPrice = Me.CurrentPrice + Me.NewBid
End If
 
Excellent Mr. B!!!! Works like a gem!!! Thank you again for all your help and
for staying with me on this. I saved the code for future use, very good to
have handy.

Thank you again!!!!
 
Back
Top