• Find Database & Delete Object (2007)

    • This topic has 2 replies, 3 voices, and was last updated 17 years ago.
    Author
    Topic
    #450516

    I am running a report from a temp table created by a make table query.

    I want to write an if…then…else statement to ensure that the temp table is deleted before I run the make table query. How would I do this?

    If ??????? then
    DoCmd.RunSQL “DROP TABLE temptable”
    else

    end if

    Viewing 1 reply thread
    Author
    Replies
    • #1106894

      The simplest way is to suppress error messages while trying to delete the table:

      On Error Resume Next
      DoCmd.RunSQL …
      On Error GoTo 0 ‘ or an error handler

    • #1106998

      In addition to Hans’ response, I do it this way

      Dim strTempTable1 As String
      strTempTable1 = "YourTableName"
      
      'check temp table existence
      If DCount("*", "MsysObjects", "[Name]='" & strTempTable1 & "'") = 1 Then
          'table exists - so delete
          DoCmd.DeleteObject acTable, strTempTable1
      Else
          'table does not exist, do nothing
      End If
      
      'call temp table create Sub
      Call CreateTempTable(strTempTable1)
      
    Viewing 1 reply thread
    Reply To: Find Database & Delete Object (2007)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: