Hello there!
I believe this is a issue that has been asked about a lot, both on here and on many other websites related to Excel (VBA) and yet I've still not been able to figure it out and to make it work for my code.
Currently I'm using a UserForm to enter data into my sheets. However, I'm required to assign a customer ID by myself which is kind of annoying because I would have to check the last customer I added manually to find out what customer ID to assign to the new one. I know this can be done automaticly and that's what I'm going for here.
What I'm working with is a UserForm that, when you click on cmdNew, allows you to enter customer details, which is then stored in a sheet called 'Klantenlijst'. 'txtKlantnr' is the textbox that should have the customer ID in it, which should be stored (and obtained) in column A, starting at row 2. So for that to work, I'd need Excel to check the values in column A and assign the highest value in the column +1 to 'txtKlantnr' whenever I click on 'cmdNew'.
I've tried several methods found on here but none seem to work for me. I do have to add that I'm very new to Excel VBA so please be thorough and specific with your tips .
Thanks in advance and my code is found below, I only copied the cmdNew code but I can provide more upon request of course.
I believe this is a issue that has been asked about a lot, both on here and on many other websites related to Excel (VBA) and yet I've still not been able to figure it out and to make it work for my code.
Currently I'm using a UserForm to enter data into my sheets. However, I'm required to assign a customer ID by myself which is kind of annoying because I would have to check the last customer I added manually to find out what customer ID to assign to the new one. I know this can be done automaticly and that's what I'm going for here.
What I'm working with is a UserForm that, when you click on cmdNew, allows you to enter customer details, which is then stored in a sheet called 'Klantenlijst'. 'txtKlantnr' is the textbox that should have the customer ID in it, which should be stored (and obtained) in column A, starting at row 2. So for that to work, I'd need Excel to check the values in column A and assign the highest value in the column +1 to 'txtKlantnr' whenever I click on 'cmdNew'.
I've tried several methods found on here but none seem to work for me. I do have to add that I'm very new to Excel VBA so please be thorough and specific with your tips .
Thanks in advance and my code is found below, I only copied the cmdNew code but I can provide more upon request of course.
Code:
Private Sub cmdNew_Click()
blnNew = True
txtKlantnr.Text = ""
txtTitel.Text = ""
txtVnaam.Text = ""
txtAnaam.Text = ""
txtStraat.Text = ""
txtPcode.Text = ""
txtStad.Text = ""
txtTelefoon.Text = ""
txtEmail.Text = ""
cmdClose.Caption = "Annuleren"
cmdNew.Enabled = False
cmdDelete.Enabled = False
cmdSave.Enabled = True
cmdFactuur.Enabled = False
Frame2.Enabled = True
txtKlantnr.Enabled = False
txtTitel.Enabled = True
txtVnaam.Enabled = True
txtAnaam.Enabled = True
txtStraat.Enabled = True
txtPcode.Enabled = True
txtStad.Enabled = True
txtTelefoon.Enabled = True
txtEmail.Enabled = True
Label2.Enabled = True
Label5.Enabled = True
Label4.Enabled = True
Label3.Enabled = True
Label6.Enabled = True
Label7.Enabled = True
Label8.Enabled = True
Label9.Enabled = True
Label10.Enabled = True
ComboBox1.Enabled = False
ComboBox2.Enabled = False
ComboBox1.Text = ""
ComboBox2.Text = ""
OptionButton1.Enabled = False
OptionButton2.Enabled = False
End Sub