Remote Add Record To A Open Table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

From another form, I've been trying to add a record to a table that is open in a subform.

Aiming to write directly to the controls, I have tried
DoCmd.GoToRecord , "subform", acNewRec
That doesn't work, I guess because "subform" is a control and not open as far as DoCmd is concerned

Then I tried another route, hoping to Invoke the AddNew method:
rst1 = New ADODB.Recordset
rst1.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\My.mdb;"
rst1.Open "tblTransactionDetail", , adOpenKeyset, adLockOptimistic, _
adCmdTable

A non-starter because the table is already open in the other form's subform control, I guess. How would you remotely get ahold of a new record appearing in subform control?
Thanks for your time and talent.
 
Jim said:
From another form, I've been trying to add a record to a table that is open in a subform.

Aiming to write directly to the controls, I have tried
DoCmd.GoToRecord , "subform", acNewRec
That doesn't work, I guess because "subform" is a control and not open as far as DoCmd is concerned

Then I tried another route, hoping to Invoke the AddNew method:
rst1 = New ADODB.Recordset
rst1.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\My.mdb;"
rst1.Open "tblTransactionDetail", , adOpenKeyset, adLockOptimistic, _
adCmdTable

A non-starter because the table is already open in the other form's subform control, I guess. How would you remotely get ahold of a new record appearing in subform control?


Not sure about using ADO for this, but here's a simple
DAOapproach

With subformcontrol.Form.RecordsetClone
.AddNew
!fielda = 123
!fieldb = "abc"
.Update
subformcontrol.Form.Bookmark = .LastModified
End With
 
You are correct that the subform of an open form is not part of the forms
collection, and thus not directly accessible by DoCmd.GoToRecord.

However, as long as the subform has focus, DoCmd.GoToRecord will work.

If your code is on the main form, you can use:

Me.YourSubformControlName.SetFocus
DoCmd.GoToRecord , , acNewRec

If your code is somewhere else, you can use:

Forms!frmYourMainForm!YourSubformControlName.SetFocus
DoCmd.GoToRecord , , acNewRec

As far as your code goes, it is quite incomplete. Without knowing what you
are trying to accomplish, it's hard to say how to complete it.

Good luck.

Sco

Jim Shores said:
From another form, I've been trying to add a record to a table that is open in a subform.

Aiming to write directly to the controls, I have tried
DoCmd.GoToRecord , "subform", acNewRec
That doesn't work, I guess because "subform" is a control and not open as far as DoCmd is concerned

Then I tried another route, hoping to Invoke the AddNew method:
rst1 = New ADODB.Recordset
rst1.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\My.mdb;"
rst1.Open "tblTransactionDetail", , adOpenKeyset, adLockOptimistic, _
adCmdTable

A non-starter because the table is already open in the other form's
subform control, I guess. How would you remotely get ahold of a new record
appearing in subform control?
 
I have a same problem w/ Jim and I thought of the same solution as you did.
As a matter of a fact, I wrote exact same code. But, for some reason, I
cannot have the access have focus on the subform. The name of the form is
"frmInput" and the name of the subform is "SbfrmExcptInstatnce."And the
"Exception instance" is where I want to put the cursor. Here is the code that
I wrote:

Forms!frmInput!SbfrmExcptInstatnce.Form![Exception instance].SetFocus
DoCmd.GoToRecord , , acNewRec

Pleaes let me know what's wrong w/ it. Thank you.

If you could
 
Back
Top