keep listbox filled (1 Viewer)

megatronixs

Registered User.
Local time
Today, 13:29
Joined
Aug 17, 2012
Messages
719
Hi al,

I created a database that keeps all emails stored. The form looks pretty much as outlook to make things logical. In the form I have 2 listboxes that act as the folders and subjects of the emails and then I have the reading pane. The first listbox shows all the folder there are, When I select a folder, all the emails that it contain show up in the second listbox. When I select a subject from an email, it will show the data inside the "reading pane" in the form (based on the ID nr that the email has). When I click on the email and it shows up, all the subjects from the second listbox disappear. How can I change the below code so that it will not happen? Any help to solve this mystery would be appreciated.

Greetings.

Code:
Option Compare Database
Option Explicit

Private Sub Command24_Click()

Application.FollowHyperlink [MailLink]

End Sub

Private Sub List28_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frml_eMail_Archive"

stLinkCriteria = "[ID]=" & Me!
[List28]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

Private Sub ListFolders_AfterUpdate()
    On Error Resume Next
    List28.RowSource = "Select tbl_eMail_Archive.ID, tbl_eMail_Archive.Subject " & _
        "FROM tbl_eMail_Archive" & _
        " WHERE tbl_eMail_Archive.FolderName = '" & ListFolders.Value & "' " & _
        "ORDER BY tbl_eMail_Archive.ID;"
End Sub

Private Sub Form_Current()
    On Error Resume Next
' Synchronise country combo with existing city
    ListFolders = DLookup("[FolderName]", "tbl_eMail_Archive", "[Subject]='" & List28.Value & "'")
' Synchronise city combo with existing city
    List28.RowSource = "Select tbl_eMail_Archive.ID, Select tbl_eMail_Archive.ID " & _
        "FROM  tbl_eMail_Archive " & _
        " WHERE tbl_eMail_Archive.FolderName = '" & ListFolders.Value & "' " & _
        "ORDER BY tbl_eMail_Archive.ID;"
End Sub
 

smig

Registered User.
Local time
Today, 14:29
Joined
Nov 25, 2009
Messages
2,209
What are list28 and command24 ?
Why dont you give your objects normal names ?
 

megatronixs

Registered User.
Local time
Today, 13:29
Joined
Aug 17, 2012
Messages
719
Hi,
List28 is te second listbox in the form that holds the subject from the emails, command24 is a button that opens the selected email (.msg from outlook). I tend to name them, but in this case I was trying to make things work and just used them as they where inserted in the form.

Greetings.
 

megatronixs

Registered User.
Local time
Today, 13:29
Joined
Aug 17, 2012
Messages
719
Hi,
Please find attached the example database. Did something wrong and now I don't get the second listbox filled in.

Greetings
 

Attachments

  • Email_Archive.mdb
    260 KB · Views: 109

smig

Registered User.
Local time
Today, 14:29
Joined
Nov 25, 2009
Messages
2,209
there are no forms in your db
 

megatronixs

Registered User.
Local time
Today, 13:29
Joined
Aug 17, 2012
Messages
719
Hi,

I just added the wrong one. Please find the correct one.

Greetings.
 

Attachments

  • Email_Archive.mdb
    640 KB · Views: 103

smig

Registered User.
Local time
Today, 14:29
Joined
Nov 25, 2009
Messages
2,209
what should be the RowSource of Lst_Subject ?

In Edit mode it has no RowSource.

In run mode it has this RowSource:
Select tbl_eMail_Archive.ID, Select tbl_eMail_Archive.ID FROM tbl_eMail_Archive WHERE tbl_eMail_Archive.FolderName = '' ORDER BY tbl_eMail_Archive.ID;
This one has errors in it.
 

megatronixs

Registered User.
Local time
Today, 13:29
Joined
Aug 17, 2012
Messages
719
Hi,

If I'm not mistaken, it should show only subjects from emails that have the folder name as from the listbox lst_FolderName selected. I will find the working copy I have and check the rowsource. The problem I have when I select an subject from the listbox lst_subject, a code is run on click and shows me the email, but then the listbox lst_subject is cleared and I need again to select the folder name from lst_FolderName.
(not really efficient).

Greetings.
 

megatronixs

Registered User.
Local time
Today, 13:29
Joined
Aug 17, 2012
Messages
719
Hi,
Please find attached a new version where you can see it working and how the listbox lst_Subject is emptied after selecting it.

Greetings.
 

Attachments

  • Email_Archive (1).mdb
    640 KB · Views: 112

smig

Registered User.
Local time
Today, 14:29
Joined
Nov 25, 2009
Messages
2,209
what do you expect to happen when you reopen the same form ?
DoCmd.OpenForm stDocName, , , stLinkCriteria

create the details as a SubForm and set it's RecordSource after updating the lst_Subject, exactly the same way you set the lst_Subject after you update the lst_Folder.
 

megatronixs

Registered User.
Local time
Today, 13:29
Joined
Aug 17, 2012
Messages
719
Hi Smig,

You are totally right :) what was I expecting with re oping the same form. I was hopping that it would be working, but as my knowledge is so limmited on vba, I had that one coming.
I will do as you said above and let you know if I managed (or ask for some tips).

Greetings.
 

megatronixs

Registered User.
Local time
Today, 13:29
Joined
Aug 17, 2012
Messages
719
Hi Smig,

I tried to follow the above, but I don't understand it correctly and get nothing working. The subform opens because the button tells it to open with the correct email. Maybe there is a different way to not to open the subform, but to show the data refreshed?

maybe in the below code somewhere?
Code:
Private Sub ListFolders_AfterUpdate() 'this could be the subform name?
    On Error Resume Next
    ListSubject.RowSource = "Select tbl_eMail_Archive.ID, tbl_eMail_Archive.Subject, tbl_eMail_Archive.ReceivedTime " & _
        "FROM tbl_eMail_Archive" & _
        " WHERE tbl_eMail_Archive.FolderName = '" & ListFolders.Value & "' " & _
        "ORDER BY tbl_eMail_Archive.ReceivedTime DESC;"
        

        
End Sub

Greetings.
 

mattkorguk

Registered User.
Local time
Today, 12:29
Joined
Jun 26, 2007
Messages
301
Try removing the 'Form_Current' section as that's refreshing the 'Lst_Subject', therefore clearing the contents.
 

megatronixs

Registered User.
Local time
Today, 13:29
Joined
Aug 17, 2012
Messages
719
Hi mattkorguk,

Thanks, that worked out :)
I did not know that it would be that easy, I really have plenty things to learn and I appriate all the help in this forum. Keep up the good work!

Greetings.
 

smig

Registered User.
Local time
Today, 14:29
Joined
Nov 25, 2009
Messages
2,209
I recreated forms from scratch for you
Hope it will give you a good start
 

Attachments

  • Email_Archive .mdb
    804 KB · Views: 84

megatronixs

Registered User.
Local time
Today, 13:29
Joined
Aug 17, 2012
Messages
719
Hi Smig,

Great solution :)
BIG thanks for your kind help.

Greetings.
 

Users who are viewing this thread

Top Bottom