Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lable Captions not showing

Status
Not open for further replies.

webstaff

Technical User
Jan 2, 2003
97
GB
Hey Guys,

Here is my first attenpt to manually connect to my database in VB6,
I have a global var called "dname"

The code is running without errors, but the lables i have on the form do not show any captions??

Can anyone suggest what i have missed.

Thanks in advance
Les

Private Sub Form_Load()
Label1.Caption = dname
Dim MyQuery As String
MyQuery = dname
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\webstaff\Desktop\sbtProgramme\sbt.mdb;"
RecordSource = "SELECT * FROM qry_sbt_FULL WHERE field_kcname = MyQuery"
End Sub

Private Sub SetDataSource()
Set lblFocus.DataSource = db
Set lblsire.DataSource = db
Set lbldam.DataSource = db
Set lblgsire1.DataSource = db
Set lblgdam1.DataSource = db
Set lblgsire2.DataSource = db
Set lblgdam2.DataSource = db
Set lblgsire3.DataSource = db
Set lblgdam3.DataSource = db
Set lblgsire4.DataSource = db
Set lblgdam4.DataSource = db
Set lblgsire5.DataSource = db
Set lblgdam5.DataSource = db
Set lblgsire6.DataSource = db
Set lblgdam6.DataSource = db
End Sub

Private Sub BindData()
' Bind fields to related Labels
lblFocus.Caption = "field_kcname"
lblsire.Caption = "Sire"
lbldam.Caption = "Dam"
lblgsire1.Caption = "sires_Gsire"
lblgdam1.Caption = "sires_Gdam"
lblgsire2.Caption = "dams_Gsire"
lblgdam2.Caption = "dams_Gdam"
lblgsire3.Caption = "Gsire2"
lblgdam3.Caption = "Gdam2"
lblgsire4.Caption = "Gsire3"
lblgdam4.Caption = "Gdam3"
lblgsire5.Caption = "Gsire4"
lblgdam5.Caption = "Gdam4"
lblgsire6.Caption = "Gsire5"
lblgdam6.Caption = "Gdam5"

End Sub

Private Sub mnuclose_Click()
MsgBox "Are you sure want to quit?", 32, "Exit"
Unload Me
End Sub


 
Change .Caption to .DataField [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanks CCLINT,
Sadly no change,
Would there be a problem because im trying to pull data from a query inside the database rather than a table?
Thanks again
Les




Private Sub Form_Load()
Label1.Caption = dname
Dim MyQuery As String
MyQuery = dname
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\webstaff\Desktop\sbtProgramme\sbt.mdb;"
RecordSource = "SELECT * FROM qry_sbt_FULL WHERE field_kcname = MyQuery"
End Sub

Private Sub SetDataSource()
Set lblFocus.DataSource = db
Set lblsire.DataSource = db
Set lbldam.DataSource = db
Set lblgsire1.DataSource = db
Set lblgdam1.DataSource = db
Set lblgsire2.DataSource = db
Set lblgdam2.DataSource = db
Set lblgsire3.DataSource = db
Set lblgdam3.DataSource = db
Set lblgsire4.DataSource = db
Set lblgdam4.DataSource = db
Set lblgsire5.DataSource = db
Set lblgdam5.DataSource = db
Set lblgsire6.DataSource = db
Set lblgdam6.DataSource = db
End Sub

Private Sub BindData()
' Bind fields to related Labels
lblFocus.DataField = "field_kcname"
lblsire.DataField = "Sire"
lbldam.DataField = "Dam"
lblgsire1.DataField = "sires_Gsire"
lblgdam1.DataField = "sires_Gdam"
lblgsire2.DataField = "dams_Gsire"
lblgdam2.DataField = "dams_Gdam"
lblgsire3.DataField = "Gsire2"
lblgdam3.DataField = "Gdam2"
lblgsire4.DataField = "Gsire3"
lblgdam4.DataField = "Gdam3"
lblgsire5.DataField = "Gsire4"
lblgdam5.DataField = "Gdam4"
lblgsire6.DataField = "Gsire5"
lblgdam6.DataField = "Gdam5"

End Sub

Private Sub mnuclose_Click()
MsgBox "Are you sure want to quit?", 32, "Exit"
Unload Me
End Sub

 
Oh yes...

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset

Then, replace

RecordSource = "SELECT * FROM qry_sbt_FULL WHERE field_kcname = MyQuery"

with

rs.ActiveConnection = db
rs.CursorType = adOpenStatic
rs.Open "SELECT * FROM qry_sbt_FULL WHERE field_kcname = '" & MyQuery & "'",Options:=adCmdText

Assumming dname is criteria for the field field_kcname
Try it with-out the WHERE criteria first...


[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Hi

Ok with that alterations it comes up with an error box which says,

"The connection cannot be used to perform this operation. Its either closed or invalid in this context."

The line of code thats highlighted in the debug option is my connection string??

rs.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\webstaff\Desktop\sbtProgramme\sbt.mdb;"

thanks again les
 

What are you doing all of a sudden this against the recordset object like this for?

rs.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\webstaff\Desktop\sbtProgramme\sbt.mdb;"

Leave all the code you had before and just relace the one line I mentioned.

First, you should add a new data form (VB Data Form Wizard) via the menu PROJECT|ADD FORM to see how it is done, and do some searching in this forum on ADO connection and recordset... [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top