Issue to code

Peter_1985 2,506 Reputation points
2021-05-03T04:47:46.05+00:00

Hi,
To code below, what should DoCmd be declared?

Dim StrSQL As String
Dim InDate As Date
Dim DatDiff As Integer

InDate = Me.FromDateTxt

StrSQL = "INSERT INTO Test (Start_Date) VALUES ('" & InDate & "' );"

DoCmd.SetWarnings False
DoCmd.RunSQL StrSQL
DoCmd.SetWarnings True

Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
821 questions
{count} votes

10 answers

Sort by: Most helpful
  1. Ken Kam Hung, Lin 91 Reputation points
    2021-05-03T05:18:16.51+00:00
    0 comments No comments

  2. Peter_1985 2,506 Reputation points
    2021-05-03T05:30:52.217+00:00

    Viorel,
    Is there complete example to open Access table, clear details of table, in VBA?

    0 comments No comments

  3. DBG 2,301 Reputation points
    2021-05-03T14:48:05.56+00:00

    Hi. DoCmd is an Application object. You don't declare it, like you would a variable. You just use it.

    When you say "clear details of table," are you talking about deleting all the records?

    0 comments No comments

  4. Peter_1985 2,506 Reputation points
    2021-05-05T02:28:26.407+00:00

    Hi,
    I've got following error,
    ![93812-1g.png]1
    due to For Each line below. Please help

    Public Function TblExists(ByVal strTableName As String) As Boolean
    Dim tblN As Object
    TblExists = False
    For Each tblN In Adb.TableDefs
    If tblN.Name = strTableName Then
    TblExists = True
    Exit For
    End If
    Next tblN
    End Function

    Dim Adb As Object: Set Adb = CreateObject("Access.Application")  
    Call Adb.OpenCurrentDatabase(F1)  
    Adb.Visible = False  
    
    0 comments No comments

  5. DBG 2,301 Reputation points
    2021-05-05T03:10:34.637+00:00

    Try replacing this line,

    For Each tblN In Adb.TableDefs

    With these ones:

    Dim db As DAO.CurrentDb
    Set db=CurrentDb()
    For Each tblN In db.TableDefs

    0 comments No comments