reset field to NULL or none

M

mark r

won't work:


Private SUB commandbutton_click()

ON ERROR GOTO ERR

If ISnull(field) then
GOTO EXIT
Me.field = "none"
End IF
EXIT
exit sub
ERR
etc......

neither will this work:

If ISnull(field) then
GOTO EXIT
Me.field = NULL
End IF
EXIT
exit sub
ERR
etc......
 
D

Douglas J. Steele

In both cases, you've got your GOTO EXIT statement before your assignment
statement, so the assignment statement will never be executed. If that's
your entire code, there's certainly no reason for the GOTO statement at all.
 
R

Ronald Roberts

mark said:
won't work:


Private SUB commandbutton_click()

ON ERROR GOTO ERR

If ISnull(field) then
GOTO EXIT
Me.field = "none"
End IF
EXIT
exit sub
ERR
etc......

neither will this work:

If ISnull(field) then
GOTO EXIT
Me.field = NULL
End IF
EXIT
exit sub
ERR
etc......

Private SUB commandbutton_click()
On Error GoTo Err

If ISnull(field) then
Me.field = "none"
End IF

Exit_commandbutton_click:
Exit Sub

Err_commandbutton_click:
MsgBox Err.Description
Resume Exit_commandbutton_click
End Sub


Or the IF could look like this if there is more
logic after the IF statement that you do not want
to execute if the field is null.

If ISnull(field) then
Me.field = "none"
Exit sub
End IF

Ron
 
J

John Griffiths

Labels need to have a colon ":" at the end.
Exit is a reserved word use something else EXIT_SUB:

Private SUB commandbutton_click()
On Error Goto ERR ' no colon here

If IsNull(field) Then
Me.field = "none"
End If

Exit Sub

ERR: 'colon here
' error handler here
End Sub

Regards John
 
Top