i have created textboxes for each fields available in an existing database file in a vb form.i need to show the data in the textboxes whenever i click the command buttons next and previous.help needed
Printable View
i have created textboxes for each fields available in an existing database file in a vb form.i need to show the data in the textboxes whenever i click the command buttons next and previous.help needed
Why don't you use DBTextBOX?
this is my code
Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "datasource=E:\project1\databmdb;"
cn.Open//shows error here
str = "Select * from table"
rs.Open str, cn
Set Text1.DataSource = rs
Text1.DataField = "NAME"
end sub
In your Open method you need
cn.open (ConnectionString, optional username, optional password, optional options)
So try this
Dim cn as ADODB.Connection
Dim rs as ADODB.Recordset
dim strCN as string
Set cn = new adodb.connection
set rs = new adodb.recordset
strCN = "Provider=Microsoft.Jet.OLEDB.4.0;" & "datasource=E:\project1\databmdb;"
cn.open strCN
rs.open "Select * from table", cn, adOpenStatic, adLockReadOnly (or whatever lock method you want)
Personally I prefer not to bind the text boxes to a datasource. Typically I will use an array of text boxes and populate them in a loop
for example if there are 10 fields in the RS and an array of 10 textboxes to be populated the code may look somethign like.
Using this method the text box is not bound to the database so any changes to the data in the boxes do not have any effect on the database unless you write code to do so in your save routine. Basically the opposite of what is aboveCode:For x=0 to 9
TextBox1(x).text=RS(x)
Next
Code:For x =0 to 9
RS(x)=TextBox1(x).text
Next
I agree with DataMiser I don't like Data Controls or databound controls.