Try including something like this:
-----------------------------------------------------------
'Set up SQL to query Diagnosis table
sDiagSQL = "SELECT Diagnosis.VisitID, Diagnosis.DiagID, Diagnosis.Diag" _
& " FROM Diagnosis, Visits" _
& " WHERE Diagnosis.VisitID = Visits.VisitID" _
& " ORDER BY Diagnosis.VisitID, Diagnosis.DiagID"
Set rstDiag = gDBS.OpenRecordset(sDiagSQL)
'If nothing to process - pack up and go home
If rstDiag.BOF Or rstDiag.EOF Then
MsgBox "There are no Diagnoses to process", vbOKOnly
GoTo Exit_thisprocedure
End If
'Open 2nd connection for updating Visits
Set dbsVst = CurrentDb
'Initialise variable used in loop
iLastVisit = 0
'Loop for all Diagnoses
Do While Not rstDiag.EOF
'Read the VisitID of current diagnosis record
iThisVisit = rstDiag("VisitID"
If iLastVisit <> iThisVisit Or iLastVisit = 0 Then
'New Visit, so initialise to 1st diagnosis
iDiagnosis = 1
Else
'Same as last visit, so this is next diagnosis
iDiagnosis ++
End If
'Which column on VISTS is to be updated?
sVstCol = Choose(iDiagnosis, _
"Primary", "Secondary", "Third"
'Build SQL to update VISITS table
sVstSQL = "UPDATE Visits " _
& " SET " & sVstCol _
& " = '" & rstDiag("Diag"

_
& " WHERE VisitID = " & iThisVisit
'Update VISITS table
dbsVst.Execute (sVstSQL)
'Move to next Diagnosis
iLastVisit = iThisVisit
rstDiag.MoveNext
Loop
-----------------------------------------------------------
Note that there's no check for >3 diagnoses, but you'll know whether it's necessary.
Also I've just typed this in - so there may be small errors, but I hope you get the drift.
Good Luck