adding data from main form to subform

irade92

Registered User.
Local time
Today, 07:26
Joined
Dec 26, 2010
Messages
229
I need to add data from main form to a table and data to be seen immediately in subform in datasheet view. From time to time I need to delete a record from subform and data should be upadatet immeditale in subform.. I dont want to use split from...Any example please..
Thanks a lot
 
I need to add data from main form to a table and data to be seen immediately in subform in datasheet view....
What kind of data are you entering from a main form that needs to appear in a subform's record source? This sounds suspiciously like both forms are based on the same Table, which is a mistake for a number of reasons.
...From time to time I need to delete a record from subform and data should be upadatet immeditale in subform...
You need a custom routine to Delete your Record then Requery the Subform after the Deletion. Since this is a Datasheet View Form you cannot add a Command Button to do this, as you would on a Single View/Continuous View Form. What I do in this situation, in fact did just a couple of weeks ago in a small app I wrote, is to use the DoubleClick event of a given Textbox to do the Delete/Requery:
Code:
Private Sub TextboxName_DblClick(Cancel As Integer)
 [B]DoCmd.SetWarnings False[/B]
 DoCmd.RunCommand acCmdDeleteRecord
 [B]DoCmd.SetWarnings True[/B]
  Me.Requery
End Sub
This code assumes that you do not want the usual Access warning to pop up telling the user that they are about to Delete a Record. If, in fact, you do want this warning to pop up, merely delete the two Bold lines in the code.

Once again, more info, vis a vis the data you're talking about adding from the main form to the subform Table, would be helpful in our helping you with this.

Linq ;0)>
 
What kind of data are you entering from a main form that needs to appear in a subform's record source? This sounds suspiciously like both forms are based on the same Table, which is a mistake for a number of reasons.
You need a custom routine to Delete your Record then Requery the Subform after the Deletion. Since this is a Datasheet View Form you cannot add a Command Button to do this, as you would on a Single View/Continuous View Form. What I do in this situation, in fact did just a couple of weeks ago in a small app I wrote, is to use the DoubleClick event of a given Textbox to do the Delete/Requery:
Code:
Private Sub TextboxName_DblClick(Cancel As Integer)
 [B]DoCmd.SetWarnings False[/B]
 DoCmd.RunCommand acCmdDeleteRecord
 [B]DoCmd.SetWarnings True[/B]
  Me.Requery
End Sub
This code assumes that you do not want the usual Access warning to pop up telling the user that they are about to Delete a Record. If, in fact, you do want this warning to pop up, merely delete the two Bold lines in the code.

Once again, more info, vis a vis the data you're talking about adding from the main form to the subform Table, would be helpful in our helping you with this.

Linq ;0)>

Thanks for your replay....I use split form to enter data...and everything is going well while entering data confirming with dialog box. The code is like this:

Private Sub txtDATPRE_AfterUpdate()
Dim answer As Integer
answer = MsgBox("Are you sure", 36)
If answer = vbYes Then
DoCmd.RunCommand acCmdSaveRecord

Else
DoCmd.RunCommand acCmdUndo
Exit Sub
End If
Me.cmdPacient.Visible = False

Me.Requery
DoCmd.GoToRecord , , acNewRec

Me.mBARKOD = vbNullString
Me.mBARKOD.SetFocus

End Sub


and now after adding three or for records I need one of them to delete and positioning with the mouse on the record I got this mesage " You can't reference a property or method for a control unless the control has a focus" and when I click "Debug" it gets me this:

Private Sub cboNAZIV_GotFocus()
Me.cboNAZIV.Dropdown
End Sub

This is the first field in of the record..
How to delete a record in a split form and continue to add a new one
For deleting a record I use exactly the same code you wrote
 

Users who are viewing this thread

Back
Top Bottom