data is not getting populated

G

Guest

Hi all
I am using sql server as backend and I am creating a form in Access. This form contains several text boxes which needs to be populated with data. this data is coming from table pass

Following code does not give any error but it does not display the data either. when i go in debug mode the rst get populated with the right value. any help would be appreacited. thanks a lo

Private Sub Form_Load(

Dim strSql As Strin
Dim conString As Strin
Dim con As ADODB.Connectio
Dim rst As ADODB.Recordse

strSql = "SELECT Degree FROM pass where User_Name='mgarg'
Set con = New ADODB.Connectio
conString = "Driver={SQL Server};Server=;DataBase=;Uid=;Pwd=;
con.Properties("Prompt") = adPromptAlway

con.ConnectionString = conStrin
con.Ope

Set rst = New ADODB.Recordse

rst.Open strSql, con, adOpenForwardOnly, adLockReadOnl

Do While Not rst.EO
Degree.ControlSource = rst.Fields("Degree"
rst.MoveNex
Loo

rst.Clos
con.Clos

End Su
 
T

TC

This code doesn't make sense:
Do While Not rst.EOF
Degree.ControlSource = rst.Fields("Degree")
rst.MoveNext
Loop

Presumeably the left-hand Degree is the name of a textbox control on your
form.

(1)
Degree.Controlsource = "Degree"
- would bind that textbox to the field Degree in the underelying recordset
of a bound form;

(2)
Degree.Value = rst.Fields("Degree")
- would display the value of the Degree field of the >current record< of the
recordset, into that textbox;

Putting (2) in a loop doesn't make sense, cos that will loop through,
displaying the value from each record, without any pauses, so you will end
up just seeing the value from the very last record.

Setting Degree.Controlsource to the >value< of the Degree field of the
recordset, doesn't make sense, unless the >value< of that field in the
recordset, is the >name< of an underlying field in the recordset of a bound
form!

HTH,
TC


mgarg said:
Hi all,
I am using sql server as backend and I am creating a form in Access. This
form contains several text boxes which needs to be populated with data. this
data is coming from table pass.
Following code does not give any error but it does not display the data
either. when i go in debug mode the rst get populated with the right value.
any help would be appreacited. thanks a lot
 
D

Dirk Goldgar

mgarg said:
Hi all,
I am using sql server as backend and I am creating a form in Access.
This form contains several text boxes which needs to be populated
with data. this data is coming from table pass.

Following code does not give any error but it does not display the
data either. when i go in debug mode the rst get populated with the
right value. any help would be appreacited. thanks a lot

Private Sub Form_Load()

Dim strSql As String
Dim conString As String
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset

strSql = "SELECT Degree FROM pass where User_Name='mgarg'"
Set con = New ADODB.Connection
conString = "Driver={SQL Server};Server=;DataBase=;Uid=;Pwd=;"
con.Properties("Prompt") = adPromptAlways

con.ConnectionString = conString
con.Open

Set rst = New ADODB.Recordset

rst.Open strSql, con, adOpenForwardOnly, adLockReadOnly

Do While Not rst.EOF
Degree.ControlSource = rst.Fields("Degree")
rst.MoveNext
Loop

rst.Close
con.Close

End Sub

Is this in a regular Access .mdb file, or in and Access Data Project?
It sounds as though you are trying to bind your form to this SQL Server
table. If it's an .mdb file, why don't you just create a linked table
(linked to the SQL-S table) and set your form's recordsource to the
linked table, or a query of it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top