Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send records from a form to anther form with subform

Status
Not open for further replies.

tanolalano

Technical User
Jul 7, 2003
27
IT
Hi all,
I have a search form(#1) to retrive some records. As well, when I filter records with combos I get a list of records. I create a button to send a single record to another form(#2) and It works well.
But I need, sometimes, to send all filtered records to a subform in onother form(#3).
How do I send records to the subform of the form(#3)?
Thanks in advance
 
How are ya tanolalano . . .

You can use an insert query/SQL to append the records to the underlying table of form3 . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Thanks TheAceMan1...can you be more explicit
I'm newbie of VBA.
Hope this help you...
I need on click event (btn#x) to open a form(#3) and send all view records.
Then adding new record in the form#3(on open) I relate information to all records present in the subform (sended from form#1).


Thanks
 
tanolalano . . .

In microsoft help (Contents Tab), navigate to:

[blue]Microsoft Jet SQL Reference
Microsoft Jet SQL Reference
Data Manipulation Language
Insert Into Statement[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Private Sub Comando45_Click()
I try to figure out the problem with this code:
Code:
Private Sub btn1_Click()
Dim strSql As String
Set RS = Me.RecordsetClone
Do While Not RS.EOF
strSql = "INSERT INTO riepilogo_mov_dare (id_acq)" _
& " SELECT Acquisti.id_acq FROM Acquisti " _
& " WHERE id_acq = RS.id_acq;"
CurrentDb.Execute strSql, dbFailOnError
Loop
End Sub

But I Get an error: Runtime error '3061'...
I'm going to be crazy!!

I need to insert the found records in the tbl "riepilogo_mov_dare" (many-to-many Table) and relate to one id of the 2nd Key.
Any help will be appreciated



 
Replace this:
& " WHERE id_acq = RS.id_acq;"
with this:
& " WHERE id_acq = " & RS.id_acq

Note: the above code assumes that id_acq is defined as numeric in Acquisti.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You're right PHV. The id_acq is numeric.
I try your change but Access crashes. :(
 
Perhaps RS.MoveNext before the Loop instruction ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Now on click the code create over 300.000 records in the table whit the same id_acq (the first in the continuos form#1)
 
Here the actual code

Code:
Private Sub btn1_Click()
Dim strSql As String
Set RS = Me.RecordsetClone
Do While Not RS.EOF
strSql = "INSERT INTO riepilogo_mov_dare (id_acq)" _
& " SELECT Acquisti.id_acq FROM Acquisti " _
& " WHERE id_acq = " & RS.id_acq
CurrentDb.Execute strSql, dbFailOnError
RS.MoveNext
Loop
End Sub
 
Thanks a lot for helping me, PHV and TheAceman.

I add the 2 red lines and now code works well. It do the right thing

Code:
[COLOR=#ff0000]If Not RS.EOF Then [/color]
Dim strSql
    Do While Not RS.EOF
        strSql = "INSERT INTO riepilogo_mov_dare (id_acq)" _
        & " SELECT Acquisti.id_acq FROM Acquisti " _
        & " WHERE id_acq = " & RS.id_acq
        CurrentDb.Execute strSql, dbFailOnError
        RS.MoveNext
    Loop
[COLOR=#ff0000]End If[/color]
 
Good for you tanolalano . . .

Bravo! . . . Bravo! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
AceMan, do you speak italian?
So when i'm in difficoul with english i use italian whit you ;)


 
tanolalano . . .

Unfortunately no. [sad] However I had no problem with the english you presented here! [thumbsup2]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top