copy records from subform to another

FahadTiger

Member
Local time
Today, 04:40
Joined
Jun 20, 2021
Messages
120
Hi Experts
I have subform (TestF).. when I check select every time copy the test name to subform (patientTestingF) ..and when click on select all ..copy all testName to (patientTestingF)
I used this code..but it used the same record every time I selected and not going to new record..any Advise pleas?
thanks ALL
Private Sub isActive_AfterUpdate()

If Me.isActive = True Then

Forms![PatientcheckupF]![patientTestingF].SetFocus

Forms![PatientcheckupF]![patientTestingF].Form![testName] = Me.testName

Forms![PatientcheckupF]![patientTestingF].Form![testPrice] = Me.testPrice

End If

End Sub
 

Attachments

  • copy Records.png
    copy Records.png
    13.9 KB · Views: 90
run append query : source data using source master form key, to target master key on form2
then refresh subform2
 
Forms![PatientcheckupF]![patientTestingF].Form![testName] = Me.testName
Me refers to the current record. If this is not changed, nothing will change.

However, you should keep in mind that records are stored in tables. Forms only display them. The content of a table can be displayed by several forms. So you don't need to copy anything, just use the same RecordSource for the new form and the list of selected ID's for targeted filtering.
Or you filter directly in the original form.
 
tkank you Ranman256 for Replying
I know to use Appending ,, but it is not work..i think because the related id of sub form with main ? i don know exactly why not working.. this is my demo
 

Attachments

Forms![PatientcheckupF]![patientTestingF].Form![testName] = Me.testName
Me refers to the current record. If this is not changed, nothing will change.

However, you should keep in mind that records are stored in tables. Forms only display them. The content of a table can be displayed by several forms. So you don't need to copy anything, just use the same RecordSource for the new form and the list of selected ID's for targeted filtering.
Or you filter directly in the original form.
you mean to use recordset to add records to table patientTestingT AND then refresh patientTestingF to display the records?
 
Your query 1 needs to also insert the CHKID. This is a foreign key on an enforced referential integrity. Seem to me the main form should be bound to a patient checkup and then you pass that ID too.
 
i cant make
Your query 1 needs to also insert the CHKID. This is a foreign key on an enforced referential integrity. Seem to me the main form should be bound to a patient checkup and then you pass that ID too.
i cant make CHKID in test table because it just refference table i select what i want and copy to subform patientTestingF which related with main by CHKID
 
That makes no sense.
You are assigning tests to a checkup so you have to have a checkup if. If not then it is a meaningless list of random tests.
 
Why did i choose this method? Because I have to choose the main examination(category), from which the secondary tests are branched. With each main examination, I choose the secondary examinations(tests), which in turn move to the sub-form(patientTestingF) that is related to the main form.

The second problem that I will face is how to transfer the patient's name to that patientTestingF so that I can benefit from it in quiries
 
im trying to use this cod .. but tell (too few parameter)
Private Sub isActive_AfterUpdate()
If Me.isActive = True Then
Dim db As DAO.Database
Set db = CurrentDb
Dim rst As DAO.Recordset
Dim StrSQL As String
Set db = CurrentDb


Set rst = db.OpenRecordset("SELECT testName,testPrice, Test.isActive FROM Test WHERE (((isActive)=True));", dbOpenDynaset)
' rst.MoveFirst
Do Until rst.EOF
StrSQL = "INSERT INTO patientTesting (testName, testPrice) VALUES (" & rst!testName & "," & rst!testPrice & ")"
DoCmd.SetWarnings False
db.Execute StrSQL, dbFailOnError
DoCmd.SetWarnings True
rst.MoveNext
Loop

Set rst = Nothing
Set db = Nothing

End If
Forms![PatientcheckupF]![patientTestingF].Requery
End Sub
 

Attachments

  • too few parameter.png
    too few parameter.png
    25.8 KB · Views: 88
I think I'm going in the wrong direction..I'll try to change my plan again
 

Users who are viewing this thread

Back
Top Bottom