How to add a record to a table?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sueb
    Contributor
    • Apr 2010
    • 379

    How to add a record to a table?

    I'm writing a little piece of code to go behind a form that needs to add records to an existing table. Here's the line that VBA doesn't like:

    Code:
            AllocationsRecordSet.AddNew ( _
                Array("Month", "Service Category", "Minutes") _
              , Array("Month_Begin", ServicesRecordSet.Fields("Service_Category"), "Months_Minutes"))

    The error says:

    Compile error: Expected: =

    I read a little (always a dangerous thing) about how to use AddNew, so I'm trying to supply the field names in the first Array, and the values in the second Array. My first field value is a date, my second is a string, and the last is an integer.
  • Brian Connelly
    New Member
    • Jan 2011
    • 103

    #2
    Try .AddRange(varia ble)
    more here

    Comment

    • gershwyn
      New Member
      • Feb 2010
      • 122

      #3
      The AddNew method does not take any arguments, it just creates a new blank record for you to fill in. I'm not sure where you got the syntax you're using.

      Try something like this:
      Code:
      With AllocationsRecordSet
        .AddNew
        !Month = Month_Begin
        ![Service Category] = ServicesRecordSet!Service_Category
        !Minutes = Month_Minutes
        .Update
      End With

      Comment

      Working...