Hello,
I have a main Case form, that when I click a button, a new Client form opens. On the Client form, I have 3 text boxes that users use to create a new client, first name, last name, and date of birth. I also have 2 invisible text boxes named Client name and ID that I ended up creating due to one of the problems I am encountering. All text boxes are bound from the Clients table, and the client name is just the first and last concatenated. I then have an Add New Client button. On the Clients table, the ID is the primary key and the first, last, and dob fields are all required and indexed to all be unique before the client is added to the table.
What I want, is for after the first, last, and dob text boxes are filled out, when I click Add New button, the client ID that was automated from the entry as well as the concatenated client name are populated into the Main form and the Client form closes.
If they didn't fill out all 3 fields, then a message states that all three fields are required. They then have to enter the information and try again. Then, if they enter all three fields, if all three are not unique, a message states that the client already exists. They should then be able to look at the listbox that is on the same form and choose the client.
I am having trouble with the error handling. I have tried different ways and nothing works. The closest I came to was getting the message to state client exists but the form closed so they couldn't access the listbox then. Here is my code so far with no error handling.
Any help would be appreciated. Thank you.
I have a main Case form, that when I click a button, a new Client form opens. On the Client form, I have 3 text boxes that users use to create a new client, first name, last name, and date of birth. I also have 2 invisible text boxes named Client name and ID that I ended up creating due to one of the problems I am encountering. All text boxes are bound from the Clients table, and the client name is just the first and last concatenated. I then have an Add New Client button. On the Clients table, the ID is the primary key and the first, last, and dob fields are all required and indexed to all be unique before the client is added to the table.
What I want, is for after the first, last, and dob text boxes are filled out, when I click Add New button, the client ID that was automated from the entry as well as the concatenated client name are populated into the Main form and the Client form closes.
If they didn't fill out all 3 fields, then a message states that all three fields are required. They then have to enter the information and try again. Then, if they enter all three fields, if all three are not unique, a message states that the client already exists. They should then be able to look at the listbox that is on the same form and choose the client.
I am having trouble with the error handling. I have tried different ways and nothing works. The closest I came to was getting the message to state client exists but the form closed so they couldn't access the listbox then. Here is my code so far with no error handling.
Code:
Private Sub AddNewClient_Click() If IsNull([First Name]) Or IsNull([Last Name]) Or IsNull(DOB) Then MsgBox "All fields are required", vbOKOnly, "Error" End If If Me.First_Name <> "" And Me.Last_Name <> "" And Me.DOB <> "" Then Dim ClName As Variant Dim ClientID As Integer ClientID = Me.Client_ID.Value ClName = Me.Client_Name.Value Forms![Case]![Client ID].Value = ClientID Forms![Case]![Client].Value = ClName Forms![Case]![Date Requested].Enabled = True Forms![Case]![Staff Requesting].Enabled = True Forms![Case]![Language Requested].Enabled = True Forms![Case]![Service Requested].Enabled = True Forms![Case]![Service Date].Enabled = True Forms![Case]![Outcome].Enabled = True Forms![Case]![Date Requested].SetFocus DoCmd.Close acForm, "Client", acSaveYes End If End Sub
Comment