MS Access Moving records to fields

I have an ODBC connection to a database that I do not own and cannot change. What I want to do is to make related records written off in one record. Relationships range from 1 to many.

I have a student management system and want to export a call list that transfers an automatic callout service (charged on call). I want to be able to call the house only once if several students live there.

Desired Outgoing Call Structure Structure:

PHONE     Inst1                  Inst2                  Inst3
555-5555  John was absent today  Jane was absent today  Joe was absent today

in accordance with existing data:

PHONE     Inst
555-5555  John was absent today  
555-5555  Jane was absent today  
555-5555  Joe was absent today

Any suggestions?

+3
source share
1 answer

-; , .

, VBA , , (- - , , -)?

dim strAbsent as string
dim currPhone as string
dim lastPhone as string
Dim db As Database
Dim rstAbsent As Recordset
Dim rstAbsentReport As Recordset

Set db = CurrentDb
Set rstAbsent = dbV.OpenRecordset("select * from Absent", _
                                    dbOpenDynaset, dbSeeChanges)
Set rstAbsentReport = dbV.OpenRecordset("select * from AbsentReport", _
                                        dbOpenDynaset, dbSeeChanges)

'...
do while not rstAbsentReport.EOF
    currPhone = rstAbsentReport("phone")
    lastPhone = currPhone 
    do while currPhone = lastPhone _
            and not rstAbsentReport.EOF
        strAbsent = strAbsent & ";" & rstAbsentReport ("comment")
        'Yes I know concatenating strings this way is terribly inefficient

        rstAbsentReport.MoveNext
        if not rstAbsentReport.EOF then
            currPhone = rstAbsentReport("phone")
        end if
    last
    rstAbsent.AddNew
    rstAbsent ("call") = strAbsent
    rstAbsent.Update
loop
'... clean up of recordset variables left as an exercise
+1

Source: https://habr.com/ru/post/1702142/


All Articles