?
Solved

Using VB6, how do i refernece a sql query with three tables

Posted on 2003-03-01
6
Medium Priority
?
184 Views
Last Modified: 2010-05-01
Hi,
    I have an sql statement which selects all the information in 3 tables and then takes it in to VB as an object “objRS” see below :-
    Set objConn = New ADODB.Connection
    Set objRS = New ADODB.Recordset
    Dim objErr As ADODB.Error
    Dim check As Boolean
    Dim Check1 As Boolean
                       
    objConn.Open "Driver=SQL Server; Server=BOSS;" & _
                "Database=Project"
               
    If objConn.State = adStateOpen Then
      'Open a recordset
                       
        objRS.Open "SELECT * FROM Vet, Management, Assistant ", objConn, adOpenForwardOnly, _
                       adLockReadOnly, adCmdText
       
        Do While Check1 = False
            MsgBox (objRS! M_StaffNo)
            If objRS.EOF Or objRS.BOF Then
                MsgBox "Not Found, Error in Database"
                Check1 = True
                Exit Do
            Else
                If S_no.Text = objRS!V_StaffNo Then
                    Frame_Vet.Visible = True
                    Frame_Comments.Visible = True
                    V_Salery.Text = objRS!V_Salery
                    V_Room.Text = objRS!V_Room
                    V_status.Text = objRS!V_status
                    Comment.Text = objRS!V_comments
                    Check1 = True
                End If

The problem here is:- how do I reference information from each table in the query. Is it  objRS!Vet.V_StaffNo or how do I tell the different between the data.

Thanks
Glenelly22
0
Comment
Question by:glenelly22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 18

Expert Comment

by:Sethi
ID: 8048220
Simply use the name of the field of the table in the recordset object like this:
objRs("V_comments")
0
 
LVL 18

Accepted Solution

by:
Sethi earned 200 total points
ID: 8048228
Also ensure to attach an empty string while assigning any recordset value to a textbox else you might get an error if the value is Null. Example:
 V_Salery.Text = objRS("V_Salery") & ""
0
 

Author Comment

by:glenelly22
ID: 8066631
Sethi
 Could I ask you another question?
Do you know how i could create a samll Calendar for my system.

Thanks
Glenelly22
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Sethi
ID: 8068401
There is Microsoft calender Control in VB that can be used. Go to Components>Microsoft Calender Control.
0
 

Author Comment

by:glenelly22
ID: 8068665
Thanks Sethi..
0
 
LVL 18

Expert Comment

by:Sethi
ID: 8068895
Anytime buddy.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question