Saturday, March 31, 2012

table to list

this code is to bring one coloumn in a listbox... when selecting that list corresponding values for that selection should be displayed in my text boxes kept in de form please some one help me...

thanks in advance......

Dim myDB As Database
Dim myRS As dao.Recordset
Dim tdf As TableDef

Private Sub DataList1_Click()

End Sub

Private Sub EXIT_Click()
Unload Me
End Sub

Private Sub Form_Load()
Set myDB = OpenDatabase("C:\deepesh\name.mdb")
Set myRS = myDB.OpenRecordset("details", dbOpenTable)
For Each tdf In myDB.TableDefs
name1.AddItem tdf.name
Next tdf
'If myRS.RecordCount > 0 Then
'myRS.MoveFirst
'End If
If Not myRS.EOF And Not myRS.BOF Then
myRS.MoveFirst
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
myRS.Close
Set myRS = Nothing
myDB.Close
Set myDB = Nothing
End Sub

Private Sub name1_Change()
Set myRS = myDB.OpenRecordset("select name,street1,street2,city,pincode,phone,pan_number from details where name=""& List1.Text &", dbopendybaset)
myRS.FindFirst "[name] = " & name1.Text & """"
If myRS.RecordCount > 0 Then
'If myRS.NoMatch = False Then
phone.Text = myRS("phone")
street1.Text = myRS("street1")
street2.Text = myRS("sreet2")
city.Text = myRS("city")
pincode.Text = myRS("pincode")
pincode.Text = myRS.Fields(5)
End If
Set myRS = Nothing
End Subbut how to add script i don understand i am new to vb so kindly help
You will need to add a bit of javascript to your listbox. Your spectacularly unstructured code makes it a little difficult to look at, but I figure that 'name1' is the name of your listbox. Use .Attributes.Add() to have it call a bit of javascript that populates a textbox on each click event.
Ok, I'll tell you half of it, since you ought to learn.

First, find out the javascript required to populate a textbox whenever an item in a listbox is clicked. Once you find that javascript, in your codebehind, use

name1.Attributes.Add("onClick",yourjavascripthere);

Keep in mind that the exact id of the textbox must be substituted in 'yourjavascripthere'. For this, you can use string concatenation and use textbox1.ClientId to get the client id of the textbox.
i seriously didnt understand a little bit... can we addd script in vb huh???
Yes. In your codebehind, you can dynamically add javascript to one of your controls. For that, you use name1.Attributes.Add().

So for example...

textbox1.Attributes.Add("onClick","alert('hello!');");

Will cause a messagebox to appear when someone clicks on textbox1.
This is ASP.Net forum and not the VB 6 forum. Please ask the moderators to move this thread to Classic VB forum.
Good call. (slaps forehead)

0 comments:

Post a Comment