Hi

I have tried evrything in a list box.
The listbox contain this 04-25 ene and
I will deselect 04-25 when I am going to dbclick on that item
the name "ene" shall I display in a book

Any Help

Lenny

Recommended Answers

All 8 Replies

can you show me a sample code of your?

Here comes the code for the list

This list1 box is working fine.................

Private Function List1()
Dim myDay As String
Dim day As String

  'Day = Format(Now, "yy-mm-dd")
myDay = Format(Now, "mm-dd")


Label10.Visible = True
Label10.ForeColor = vbRed
Label10.Caption = "Födelsedag Idag"

If rs.RecordCount = 0 Then

       Exit Function

End If
     rs.MoveLast
     rs.MoveFirst
     max = rs.RecordCount
     rs.MoveFirst
     LstData.Clear
    For i = 1 To max

    If Right$(rs("prn"), 5) = myDay Then

       LstData1.AddItem myDay & " " & rs("eftn") & " " & rs("Namn")
    End If
    rs.MoveNext
    Next i

and here is the code for the dbclick event in the lstdata1 box, here is the problem
that I can't get of the date and then fill the textboxes with the coresponding names.

Private Sub LstData1_DblClick()

Label10.Visible = True
Label10.Caption = "Födelsedag Idag"
Label10.ForeColor = vbRed

 Set rs = db.OpenRecordset("select * from phone where eftn + ' ' + namn = '" & _
         Trim(LstData1.List(LstData1.ListIndex)) & "'")

rs.MoveFirst

 TxtEftN.Text = rs("eftn")
 TxtFNamn.Text = rs("namn")
 TxtCO.Text = rs("careoff")
 TxtAdr.Text = rs("adress")
 TxtPostNr.Text = rs("PostNr")
 TxtPostAdr.Text = rs("PostAdr")
 TxtLand.Text = rs("Land")
 TxtPrn.Text = rs("Prn")
 TxtNd.Text = rs("NamnsD")
 TxtHTel.Text = rs("HomeTel")
 TxtmTel.Text = rs("MobTel")
 TxtATel.Text = rs("WorkTel")
 TxtEmail.Text = rs("Email")
 TxtEmail1.Text = rs("Email1")
 'TxtBarn.Text = rs("Barn")
 'TxtBarn1.Text = rs("Barn1")
 'TxtBarn2.Text = rs("Barn2")
 TxtMemo.Text = rs("Memo")

sorry if the code is very....

See this :

Set rs = db.OpenRecordset("select * from phone where eftn + ' ' + namn = '" & _
Trim(LstData1.List(LstData1.ListIndex)) & "'")

Your sql query is wrong.
You want to display data in textbox when you select listbox but you never get eftn and namn value from listbox.
Also there are no AND clause between eftn and namn

Since you separate data in lisybox with space then you can split it using space to get eftn and namn value
LstData1.AddItem myDay & " " & rs("eftn") & " " & rs("Namn")

So, split selected item on listbox before querying it to database :

    Dim temp() As String
    temp = Split(LstData1.List(LstData1.ListIndex), " ") ' spliting by space

    ' temp(1) will contain eftn from listbox and temp(2) will contain namn from lisbox
    Set rs = db.OpenRecordset("SELECT * FROM phone WHERE eftn = '" & temp(1) & "' AND namn = '" & temp(2) & "'"

    ...

thanks

I tried it and I could not get it to work

the lstdata1 box contain
04-26 cesar
04-26 en sture

what I will to do is to omitt those 04-26
in the lstdata box
and fill txtboxes with corespending text from database

see code of lstdata1_dbclick
where to put it.
The first code is function good and I will have it like that

lenny

what I will to do is to omitt those 04-26
in the lstdata box
and fill txtboxes with corespending text from database

I'm confused here.
What is in listdata1? What is the format item on lstdata1?
This is your format MyDay SPACE eftn SPACE Namn
LstData1.AddItem myDay & " " & rs("eftn") & " " & rs("Namn")
But in your last reply lstdata1 not contain all of it.

When you querying data from database what it the constrains? i mean the fields like eftn or namn.
Write your query here to make me more understand what the constraint.
You want to remove 04-26 and just get the string after it?
ex :
04-26 cesar --> will get cesar
04-26 en sture --> will get en sture

Also what is the use of the string?

i really don't understand the exact the Query part as well as the whole question.
what type of value for the field "eftn" and "Namn" ?

but try this :-

MsgBox Mid(LstData1.Text, 7)

the above statement will help you to extract the string after 04-26

Thanks that solve it after looking in he mssbox

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.