oAcc.DoCmd.GoToRecord,,acNewRec
-Tom.
>I am searching for a way to create multiple records in Access 2000 from
>a worksheet created in Excel. I'm pretty much self-taught with Visual
[quoted text clipped - 21 lines]
>DoCmd.GoToRecord , , acNewRec but I don't know how to reference
>something like that from Excel. Any suggestions?
super_dave_42 - 27 Feb 2006 07:23 GMT
Thanks -Tom,
Unfortunately, 'oAcc.DoCmd.GoToRecord,,acNewRec' did not work. On the
up side, it gave me no error messages. I ended up with the last row of
data transfered into the correct fields of the current record, so it
would appear each row was just overwritten by the next. I came across a
Recordset object in the help files, and the AddNew method seems like a
good alternative to DoCmd. However, Excel does not recognize the
Recordset object (fyi, I have the MS Access 9.0 Obj Lib added to my
References). The closest thing I could see is an AccessObject type. So,
I tried the following:
Dim oAcc As Object
Dim rstTable As AccessObject
...
Set oAcc = GetObject(, "Access.Application")
Set rstTable = oAcc.Forms!Form1.Recordset
...
rstTable.AddNew
...
That didn't work either, and rstTable never changed its value from
"Nothing" after the Set command was processed. So I then thought to
just let VB handle the job of determining the type.
Dim oAcc As Object
Dim rstTable As Object
...
Set oAcc = GetObject(, "Access.Application")
Set rstTable = oAcc.Forms!Form1.Recordset
...
rstTable.AddNew
...
Voila! A brand-spanking-new record for each row of my data. I can go
sleep now. :^)
p.s. One bad side effect, which doesn't bother me but might be of
interest to others, is the fact that the NewRecord property
(oAcc.Forms!Form1.NewRecord) didn't seem to change value when I used
this new code. Honestly, I don't know if it even changed with my
original code; I might have just always been using a new record. I
suggest you test more thoroughly than I have done.