Results 1 to 5 of 5
  1. #1
    Join Date
    May 2003

    Unanswered: Changind Default Error Messages

    I am trying to change my application so when errors like "This entry would create duplica values of the index...." to display a custom error. I have an "On Error" in my code, but if an error in a sql statement like the one above occurs, it displays the standard MS access error, and THEN runs my statement. How do i stop it from displaying the standard error, and just mine? I tried Doing a DoCmd.Setwarnings(-1) before my sql statement, but that prevents the MsgBox in my on error section to even pop up. Any ideas???

  2. #2
    Join Date
    Dec 2002
    Préverenges, Switzerland
    please worry a little about your setwarnings.

    docmd.setwarnings false 'set system warnings off
    'execute the stuff giving you warnings
    docmd.setwarnings true 'set system warnings on again

    suggestion: dont use -1/0: use the intrinsic constants True/False (yes there are exceptions, but setwarnings is not one of them)

    currently using SS 2008R2

  3. #3
    Join Date
    May 2003
    Here is my code - I tried your idea but my results are the same. Nothing happens - whether or not the SQL statement executes correctly.

    Private Sub cmdAddOccurrence_Click()
    On Error GoTo err_cmdAddOccurrence_Click

    If IsNull(cboAddOccurrenceName) Or IsNull(txtAddOccurrenceDate) Then
    MsgBox ("Please enter a value for both Project Name and Project Date")

    NewName = Me!cboAddOccurrenceName
    NewDate = Me!txtAddOccurrenceDate
    DoCmd.SetWarnings False
    DoCmd.RunSQL ("insert into tblProjects (ProjectName,ProjectDate) values ([Forms]![frmAdd]![cboAddOccurrenceName], [Forms]![frmAdd]![txtAddOccurrenceDate]);")
    DoCmd.SetWarnings True
    [Forms]![frmAdd]![cboAddOccurrenceName] = Null
    [Forms]![frmAdd]![txtAddOccurrenceDate] = Null
    cboProjforComp = Null

    End If
    GoTo NoError

    message = MsgBox("The project '" & NewName & "' already has an occurrence on '" & NewDate & "'. Please try again.", , "Duplicate Entry")

    End Sub

  4. #4
    Join Date
    Feb 2002
    Setwarnings will not handle that situation. That is for things like when you running a query and it will warn you that you are about to delete and things like that.

    Try looking up the item that is a duplicate. If the addoccurence is the item that you have set in your tables to not allow duplicates, then do something like

    if dcount("cboAddOccurrenceName","tblProjects","[whateveryounamed thatfield]=" & "'" & cboAddOccurrenceName & "'")>0 then
    message = MsgBox("The project '" & NewName & "' already has an occurrence on '" & NewDate & "'. Please try again.", , "Duplicate Entry")
    end if

    Add this code in the on_exit or after_update function.

  5. #5
    Join Date
    May 2003
    That was just what i needed - it worked great thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts