Require input before update & warn if duplicate

buckwheat

New Member
Joined
Feb 20, 2003
Messages
21
Help I am new and stupid.

I have a form with two list boxes and 8 text boxes. I am using an append query to update a table from a push button on the form. The two list boxes are named Area and Date. I want the two list boxes to pop up a message that says " Area and Date required " and return to the form if an area or a date is not input . Also I want a warning to pop up if these two have already been updated. Below is the code I already have. I have tried this:
"If Len(Forms!main!area) = 0 Then MsgBox "You must enter an area"
I have tried ="" and = null but neither has worked. I am at a loss for the duplicate message.
Any help will be appreciated.
Buckwheat

Private Sub Command14_Enter()
DoCmd.SetWarnings (warningsoff)
On Error GoTo Err_Command14_Click
Dim stDocName As String
stDocName = "appendfrommainmenu"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Forms!main!tload.Value = ""
Forms!main!tcharge.Value = ""
Forms!main!.tspa.Value = ""
Forms!main!.tda.Value = ""
Forms!main!.tunload.Value = ""
Forms!main!.ttraining.Value = ""
Forms!main!.tclerk.Value = ""
Forms!main!.twash.Value = ""
Forms!main!.tothernoprod.Value = ""
Exit_Command14_Click:
Exit Sub
Err_Command14_Click:
MsgBox Err.Description
Resume Exit_Command14_Click
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
To test for Nulls use the isNull() function.

If IsNull(Forms!main!area) Then
'.....

End If

To check if the area/date combination has alredy been updated you could probably use The Dcount() function using those two fields as your criteria.

HTH

Peter
 
Upvote 0
Peter,
Thanks for the quick response I tried the following

If IsNull(Forms!main!area) Then MsgBox "You must enter an area"

and nothing. I then tired making the default value in properties 0 and testing for that and nothing. Any other ideas? I know the table is blank where it updated everything else so I would think that the list box should return null.
 
Upvote 0
try opening the debug window (ctrl-G) and entering
Print Forms!main!area

This should then give you the value that the list box is returning, this might help pin down what is happening.

Peter
 
Upvote 0
Thanks, Please forgive some of my shrewd ways here. I am self taught and an operations manager.
It returned null and I have it somewhat working. The only problem I have is that if you click the button a second time without changing anything on the form it does nothing which might make these idiots I work with think that they have updated their numbers. Any ideas on how to make this reset or why it is not ending. I am going to play with the dcount next. Updated VB below:

If IsNull(Forms!main!area) Then MsgBox "You must enter an area"
If IsNull(Forms!main!area) Then GoTo exit_exit

On Error GoTo Err_Command14_Click

Dim stDocName As String
If Len(Forms!main!area) = 0 Then MsgBox "You must enter an area"

If IsNull(Forms!main!area) Then MsgBox "You must enter an area"
stDocName = "appendfrommainmenu"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command14_Click:
Exit Sub

Err_Command14_Click:
MsgBox Err.Description
Resume Exit_Command14_Click
exit_exit:
End Sub
 
Upvote 0
I have cleaned the code up a bit and added a line to print your area value to the debug window each time it runs., that may help throw some light on what is happening
Code:
Dim stDocName As String
On Error GoTo Err_Command14_Click
Debug.Print Forms!main!area
If IsNull(Forms!main!area) Then
   MsgBox "You must enter an area"
   Exit Sub
End If

stDocName = "appendfrommainmenu"
DoCmd.OpenQuery stDocName, acNormal, acEdit
   MsgBox "Record Updated"
   
Exit_Command14_Click:
Exit Sub

Err_Command14_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Command14_Click
End Sub

Peter
 
Upvote 0

Forum statistics

Threads
1,221,771
Messages
6,161,847
Members
451,723
Latest member
Rachetsely

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