SetWarning False.....?

  • Thread starter Thread starter shiro
  • Start date Start date
S

shiro

I have the following code in my form.
It works well,like I want.But I need to
put :
DoCmd.SetWarning False

but don't know where is the correct place,
so that the Access warning will not appear
again.Thank's



Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate
Dim strMessage As String
Dim intResponse As Integer
intResponse = MsgBox("Is the spec correct?", vbYesNoCancel, "Confirm")
Select Case intResponse
Case vbYes
If IsNull(Me.Model) Then
strMessage = strMessage & _
" Enter Model Name" & vbCrLf
End If

If Inputvoltage.Value < 11 Then
strMessage = strMessage & _
" Input correct voltage rate " & vbCrLf
End If

If SpeedMode_opt.Value = 2 Then
Else
If Rotationspeedlolimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If
End If

If SpeedMode_opt.Value = 2 Then
Else
If Freeaircurrentlolimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If
End If

If SpeedMode_opt.Value = 2 Then
Else
If Lockcurrentlolimit1.Value = 0 Then
strMessage = strMessage & _
" Input Lock Current spec 1 " & vbCrLf
End If
End If


If SpeedMode_opt.Value = 1 Then
Else
If Rotationspeedlolimit2.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 2 " & vbCrLf
End If
End If

If SpeedMode_opt.Value = 1 Then
Else
If Freeaircurrentlolimit2.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 2 " & vbCrLf
End If
End If

If SpeedMode_opt.Value = 1 Then
Else
If Lockcurrentlolimit2.Value = 0 Then
strMessage = strMessage & _
" Input Lock Current spec 2 " & vbCrLf
End If
End If


If Len(strMessage) = 0 Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Else
MsgBox strMessage, vbOKOnly, "Errors Occurred"
End If
DoCmd.SetWarnings False

Case vbNo
If MsgBox("Cancel spec registration? ", vbOKCancel, "Confirm") =
vbOK Then
Me.Undo
End If
Cancel = True


Case vbCancel
Cancel = True

End Select


Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox Err.Description

Resume Exit_Form_BeforeUpdate


End Sub
 
Hi,

What do you want exactly? If you put that line of code in the event, the
warning message will no longer appears. If you want to reset it back just set
it to True.
I have the following code in my form.
It works well,like I want.But I need to
put :
DoCmd.SetWarning False
but don't know where is the correct place,

Case vbCancel
Cancel = True

End Select
DoCmd.SetWarning True 'if no error
Exit_Form_BeforeUpdate:
DoCmd.SetWarning True 'if there was an error
Exit Sub

Err_Form_BeforeUpdate:
MsgBox Err.Description

Resume Exit_Form_BeforeUpdate

End Sub
 
I want the warning message from captioned Microsoft access Not longer
appear.I want the warning message come from my code only.
 
It might help if you told us what error message you want to suppress.

If it is an engine-level error (such as Invalid-data-type, or
Duplicate-index), you may be able to trap it with the Error event of the
form.
 
So far there are some error message:
1.If all meet the criteria in the code ( Len = 0 ) then there is Message
from
access :
" The macro or function set to BeforeUpdate or ValidationRule property for
this fields is preventing Microsoft Access from saving the data in the
field."

2.If PK is null
" Index or Primary key cannot contain null Value."

3.If PK is Null and the form is closed:
" You can't save this record at this time.
Microsoft Access may encountered an erro while trying to save a record.
If you close this object now,the data changes you made will be lost.
Dou you want to close the database object anyway?

It seem, Access will keep send another error message just like :
"You can't go to the specified record" if I click add new record.

Is it possible to prevent that?
 
The first 2 of those messages can be trapped in the form's Error event.

But please think carefully about what you want Access to do. If you plan to
suppress these messages, do you want Access to just silently discard the
entry *without* telling the user that their entry was not acceptable? Or do
you want it to just stubbonly sit there, refusing to close or move to
another record until they fix their error, but not inform them of this or of
what they need to fix?

The messages are there to let the user know that something's wrong and needs
their attention. If you suppress it, your choices are to cancel the whole
entry (presumably without notifying the user), or behave as if the program
is stuck/crashed until they get it right.
 
You're right Mr Allen,Thank's.
May be the better idea is changing them to my own message.
But,in what even to put the code so that the message no 2 and
3 can be change to my own mesage.

Especially for message no1:
It seems the form does have something wrong with it.Why it still
send the warning message although all the criteria is met?I click
OK,then the record entered,and I can find it in my table.Do you
know Mr.Allen? Thank's again for the lesson and your guidance.
 
If you want to create your own custom message, use the Error event of the
form.

I haven't traced what your code is actually doing. You may find the error
message is not coming from the code.
 
Try to solve the PK problem first. The code cannot save the record if there
is nothing the the PK field.

So, is the PK manually entered?
So far there are some error message:
1.If all meet the criteria in the code ( Len = 0 ) then there is Message
from
access :
" The macro or function set to BeforeUpdate or ValidationRule property for
this fields is preventing Microsoft Access from saving the data in the
field."

2.If PK is null
" Index or Primary key cannot contain null Value."

3.If PK is Null and the form is closed:
" You can't save this record at this time.
Microsoft Access may encountered an erro while trying to save a record.
If you close this object now,the data changes you made will be lost.
Dou you want to close the database object anyway?

It seem, Access will keep send another error message just like :
"You can't go to the specified record" if I click add new record.

Is it possible to prevent that?
It might help if you told us what error message you want to suppress.
[quoted text clipped - 109 lines]
 
Yes,PK manually entered.


AccessVandal via AccessMonster.com said:
Try to solve the PK problem first. The code cannot save the record if there
is nothing the the PK field.

So, is the PK manually entered?
So far there are some error message:
1.If all meet the criteria in the code ( Len = 0 ) then there is Message
from
access :
" The macro or function set to BeforeUpdate or ValidationRule property for
this fields is preventing Microsoft Access from saving the data in the
field."

2.If PK is null
" Index or Primary key cannot contain null Value."

3.If PK is Null and the form is closed:
" You can't save this record at this time.
Microsoft Access may encountered an erro while trying to save a record.
If you close this object now,the data changes you made will be lost.
Dou you want to close the database object anyway?

It seem, Access will keep send another error message just like :
"You can't go to the specified record" if I click add new record.

Is it possible to prevent that?
It might help if you told us what error message you want to suppress.
[quoted text clipped - 109 lines]
 
Then, I would suggest you include the check on this some where in your event.

If IsNull(PK) Then
msgbox "Please enter PK"
Cancel = true
me.PK.setfocus
end if
 
Back
Top