Issue to code

Peter_1985 2,686 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.
881 questions
{count} votes

10 answers

Sort by: Most helpful
  1. Peter_1985 2,686 Reputation points
    2021-05-05T03:41:53.913+00:00

    Sorry, I still get same error due to For Each line below.

    Dim db As DAO.Database
    
    Set db = DBEngine(0).OpenDatabase(F1)
    
    'db.Close
    
    If TblExists(ActiveSheet.Name) Then
        DoCmd.DeleteObject acTable, ActiveSheet.Name
    End If
    

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

    0 comments No comments

  2. DBG 2,301 Reputation points
    2021-05-05T03:50:05.543+00:00

    Hi. Looks like you're all over the place on this one. That's not what I wrote, so I'm not sure if you've tried it or not.

    Earlier, you didn't have ActiveSheet; but now, you do.

    Please stick with one approach until we fixed it. Can you share a copy of your db? That might make it easier to help you.

    0 comments No comments

  3. Peter_1985 2,686 Reputation points
    2021-05-05T03:53:55.483+00:00

  4. Peter_1985 2,686 Reputation points
    2021-05-05T04:17:27.317+00:00

    OK. Thanks. Appreciated to your help.

    Any other help on this thread?


  5. Peter_1985 2,686 Reputation points
    2021-05-05T05:05:39.127+00:00

    Hi,
    In VBA, I was stuck in event (called Write_to_Text_file) to remove details of tables (named as Activesheet.name) and to flush details from empty table t1 into such table (of Access DB). Here is Excel file.
    https://1drv.ms/x/s!Ai8CrEskdewXvn_aF-Ex_YazqAN3?e=bNaK4U


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.