Access 2010 VBA code to set a form field to null

Wingfoot

New Member
Joined
Oct 10, 2014
Messages
37
Hi

I'm trying to write some simple code that deletes the contents of a field and opens a message box if the field's number is greater than that in another field (see below):

Code:
Private Sub Confirmed_Cartons_AfterUpdate()
If [Confirmed Units] > 0 And [Confirmed cartons] > [Confirmed Units] Then [Confirmed cartons] = "" & MsgBox("Cartons and sets cannot be greater than units!")
End Sub

What actually happens is where the [Confirmed cartons] field is greater than the [Confirmed Units] field, it sets the field's value as 1 rather than deleting the number altogether which is what I want it to do.

Please could somebody enlighten me.

Thanks
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You cannot do two separate actions on a single line (and you certainly don't want to use "&" which is concatenate, which is a text function).

Try:
Code:
[COLOR=#333333]Private Sub Confirmed_Cartons_AfterUpdate()

[/COLOR]    If (Me.[Confirmed Units] > 0) And (Me.[Confirmed cartons] > Me.[Confirmed Units]) Then 
        Me.[Confirmed cartons]=Null
        MsgBox "Cartons and sets cannot be greater than units!"
    End If

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,905
Messages
6,162,772
Members
451,786
Latest member
CALEB23

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