Link to home
Start Free TrialLog in
Avatar of al4629740
al4629740Flag for United States of America

asked on

Combine sql queries so that they show up on the vb6 datagrid

How can I combine these two sql queries so that they both show up on the datagrid in vb6?  I want the first query to be combined with the bottom code.


    esql = "select H.Agency,H.RegID,R.LastName,R.FirstName, H.ActivityID,A.ActivityName,H.Narrative, H.ActivityDate, H.Program, H.Hours, ltrim(right(convert(varchar(25), H.HourTimeFrom, 100), 7)) as 'Time From', " & _
        "ltrim(right(convert(varchar(25), H.HourTimeTo, 100), 7)) as 'Time To', H.SubGroup,H.Area, H.ParticipantHour, H.VolunteerHour, H.Fiscal, H.EntryTime " & _
        "from tblOrgHours H " & _
        "JOIN tblOrgRegistrations R on H.RegID = R.RegID " & _
        "JOIN tblOrgActivities A on H.ActivityID = A.ActivityID " & _
        "Where H.AgencyID = '" & AgencyID & "' And H.ActivityDate >= '" & DTPicker1 & "' And H.ActivityDate <= '" & DTPicker2 & "'" & " " & String1 & " order by r.LastName,r.FirstName, H.Program, A.ActivityName, H.ActivityDate,H.HourTimeFrom"
        

Open in new window


esql = "select AgencyID from tblOrgProfile where [System Name] ='" & Combo1 & "'" 

If rec.State = adStateOpen Then
        rec.Close
End If

      rec.CursorType = adOpenStatic
      rec.CursorLocation = adUseClient
      rec.LockType = adLockOptimistic
      rec.Open esql, conn, , , adCmdText

Text1 = rec.RecordCount

If rec.EOF And rec.BOF Then
    Set DataGrid1.DataSource = Nothing
    MsgBox "There are no Records for this Query. ", vbOKOnly, "No Data Found"
    Exit Sub
    
End If

      
        Set DataGrid1.DataSource = rec
        
        
    rec.MoveFirst
    

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of al4629740

ASKER

Combining means no use of join but rather combine yet separate.   So that two record sets can be seen from the data grid
With a union query, you can use explicit null columns in the case queries don't have the same number of columns:
SELECT Col1, Col2, Col3
FROM MyFirstTable
UNION ALL
SELECT Col1, Null, Null
FROM MySecondTable;

Open in new window

Would it be possible for someone to demonstrate using the columns and table structure that I sent.  I took time to post those for that reason.


Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial