MysticElaine
Registered User.
- Local time
- Yesterday, 19:09
- Joined
- May 26, 2014
- Messages
- 24
Hello. I am very new to Access (just opened the program for the first time on 5/21/14). I am creating a project for work, which is coming along pretty well. I am stuck though on populating form1 from form2 after selecting an item in a listbox as well as getting the listbox to filter correctly. I need to do this in a couple of different areas. Here is my project in a nut shell
Form1 "Start" has 2 buttons, New Entry and Search.
When I click New Entry, it opens up Form 2 "frmCases", which is the main form, I guess. From here, I enter lots of data. At one point, when I click on the Client text box, it opens a third form "frmClients." This form has 3 text boxes, First Name, Last Name, and DOB. These text boxes are to not only add a client to the "Clients" table, but also are used to search the "Client List" listbox. I also have a text box that just has the concatenate of the First and Last name, which I was using to populate the previous form. What I wanted, was to make sure that the client being added was actually new. So if as they were typing in the information they saw the name pop up in the listbox, they would then click that name instead of clicking the add new client button. Regardless of if they clicked the add new client button or clicked the list box, I wanted the client's name and unique number to then be populated in the "frmClients" form.
Last night I had gotten the search boxes to sort of work, where when I typed the first name, the list box filtered, but when I typed the last name, it didn't finish filtering but also added first names with the same last name. I had also managed to get the Client name populated in the form I wanted when I clicked the add new client button. I could never get the selection from the list box to populate. Here is my code for these:
I still can't seem to figure out how to populate the form "frmCases" from the listbox selection. I have to do this with another form as well, which was a bit simpler so I was trying it there first. From my "Start" form, I could click the Searches button and it opens up the form "Search Cases." This form is simple and has one text box "Search Case" to find a case, which filters the "Search Cases List" listbox. I want to select the case from the list box, hit the edit button, and have it populate the information into the "frmCases". The most I got was for it to ask me to input an ID number, that was with this code:
I had also tried going to "frmCases" and just entering the ID control source as =Forms![Search Cases]![Search Cases List].Column(2). It worked for the first time, but when I tried again, it just stayed on that form, it wouldn't repopulate for a different selection.
Sorry for the long post. These are the only two issues I am having at the moment from getting the project completed, which I wanted to have done by Tuesday. Thank you for any and all help, it is appreciated. As I mentioned, I am brand new to Access, so whatever your reply, I would appreciate an explanation along with whatever answers you give so I can learn and not just have something to copy and paste. Thanks!
Form1 "Start" has 2 buttons, New Entry and Search.
When I click New Entry, it opens up Form 2 "frmCases", which is the main form, I guess. From here, I enter lots of data. At one point, when I click on the Client text box, it opens a third form "frmClients." This form has 3 text boxes, First Name, Last Name, and DOB. These text boxes are to not only add a client to the "Clients" table, but also are used to search the "Client List" listbox. I also have a text box that just has the concatenate of the First and Last name, which I was using to populate the previous form. What I wanted, was to make sure that the client being added was actually new. So if as they were typing in the information they saw the name pop up in the listbox, they would then click that name instead of clicking the add new client button. Regardless of if they clicked the add new client button or clicked the list box, I wanted the client's name and unique number to then be populated in the "frmClients" form.
Last night I had gotten the search boxes to sort of work, where when I typed the first name, the list box filtered, but when I typed the last name, it didn't finish filtering but also added first names with the same last name. I had also managed to get the Client name populated in the form I wanted when I clicked the add new client button. I could never get the selection from the list box to populate. Here is my code for these:
Code:
Private Sub First_Name_Change()
Dim ClSearchSQL As String
ClSearchSQL = "SELECT Clients.[First Name], Clients.[Last Name], Clients.[DOB] FROM Clients"
ClSearchSQL = ClSearchSQL & " WHERE (((Clients.[First Name]) Like '" & Me.[First Name].Text & "*'))"
ClSearchSQL = ClSearchSQL & " ORDER BY Clients.[First Name]"
Me.[Client List].RowSource = ClSearchSQL
End Sub
Private Sub Form_Load()
[Client Name].Visible = False
End Sub
Private Sub Add_New_Client_Button_Click()
Dim ClName As Variant
ClName = Me![Client Name].Value
DoCmd.Close acForm, "frmClients"
Forms![frmCases]!Client.Value = ClName
Forms![frmCases]![Language Requested].SetFocus
End Sub
Private Sub Last_Name_Change()
Dim LNSearchSQL As String
LNSearchSQL = "SELECT Clients.[First Name], Clients.[Last Name], Clients.[DOB] FROM Clients"
LNSearchSQL = LNSearchSQL & " WHERE (((Clients.[Last Name]) Like '" & Me.[Last Name].Text & "*'))"
LNSearchSQL = LNSearchSQL & " ORDER BY Clients.[First Name]"
Me.[Client List].RowSource = LNSearchSQL
End Sub
I still can't seem to figure out how to populate the form "frmCases" from the listbox selection. I have to do this with another form as well, which was a bit simpler so I was trying it there first. From my "Start" form, I could click the Searches button and it opens up the form "Search Cases." This form is simple and has one text box "Search Case" to find a case, which filters the "Search Cases List" listbox. I want to select the case from the list box, hit the edit button, and have it populate the information into the "frmCases". The most I got was for it to ask me to input an ID number, that was with this code:
Code:
Private Sub Edit_Existing_Case_button_Click()
Dim CaseList As Control, ExCaseID As Long
Set CaseList = Me![Search Cases List]
ExCaseID = CaseList.Column(2)
DoCmd.Close acForm, "Search Cases"
DoCmd.OpenForm "frmCases", acNormal, , "Forms![frmCases]![Case ID].Value=ExCaseID", acFormEdit
End Sub
I had also tried going to "frmCases" and just entering the ID control source as =Forms![Search Cases]![Search Cases List].Column(2). It worked for the first time, but when I tried again, it just stayed on that form, it wouldn't repopulate for a different selection.
Sorry for the long post. These are the only two issues I am having at the moment from getting the project completed, which I wanted to have done by Tuesday. Thank you for any and all help, it is appreciated. As I mentioned, I am brand new to Access, so whatever your reply, I would appreciate an explanation along with whatever answers you give so I can learn and not just have something to copy and paste. Thanks!
Last edited: