Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm new to programming, and I'm following an online tutorial about Excel/VBA. This code should take data from a form and input it into an Excel database.
The author of the tutorial doesn't respond to me, and I'm already quite advanced in the project, so I'd appreciate any help you can give, thank you in advance.

There is a part of the code that I can't get to work. I always make mistakes, I need your help please.

What I have tried:

VB
Private Sub btnSubmit_Click()

Application.ScreenUpdating = False

Dim Rows As Long
'data base table name and range
Rows = Folha("student_list").Range("A1048576").End(x1UP).Row + 1
'data base table name and total range

With EsteLivro.Folhas("student_list")
'insert fields

.Range("A" & Rows).Value = Rows + 9999  'this row will genetate and insert serial number
.Range("B" & Rows).Value = txtfirstname.Value
.Range("C" & Rows).Value = txtlastname.Value
.Range("D" & Rows).Value = txtemail.Value
.Range("E" & Rows).Value = txtphone.Value
.Range("F" & Rows).Value = cmbgender.Text
.Range("G" & Rows).Value = cmblevel.Text
.Range("H" & Rows).Value = cmbcountry.Text
.Range("I" & Rows).Value = cmbcity.Text
.Range("J" & Rows).Value = txtaddress.Value
.Range("K" & Rows).Value = txtcurrent_address.Value

Unload UserForm2

Application.ScreenUpdating = True
End With

End Sub
Posted
Updated 19-Sep-23 10:51am
v5
Comments
Richard MacCutchan 18-Sep-23 6:00am    
"There is a part of the code that I can't get to work. I always make mistakes, I needed your help please"
Help with what? You have not explained what the problem is.

1 solution

We have no access to your data, or any idea what that code is supposed to do - let alone what it is doing that it shouldn't.

If you are following an online tutorial, the best place to start is with the tutorial itself: ask about your problem there, and at least they know what the background is and should be able to help you, where we can't.
If they don't or can't ... find a different tutorial - the author of one you are following probably knows very little more than you do!

Quote:
Quando eu executo o código, dá o erro:
Sub, Função ou Propriedade não definida.
não sei se srá de você meu excell estar em português e a semântica é diferente,
worksheet= Folha
ThisWorkSheet = EsteLivro etc, como disse estou a me inciar em vba.
Muito obrigado



"When I run the code, it gives the error:
Sub, Function or Property not defined."

That means exactly what it says: you are trying to use a subroutine, function, or property that you haven't declared, or that you have misspelled.
If you look at the error message, it will tell you which line of your code it found the problem on, and that should tell you what you need to look for.

This may help: You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!

And spending a little time learning to understand syntax error messages will save you a huge amount of time in future: you waited at least 1/4 hour for Chris to reply, then your email system probably added another 10 minutes or so, plus the time it took you to type up the question once you had found this site and created an account. Chances are that you could have saved a significant chunk of that time if you knew how to read them!

I'm not saying we don't want to help you fix them - sometimes I can't see my own errors because I read what I meant to write - but fixing syntax errors is part of the job, and if you can't do it for yourself people are going to look at you as a bit weird should you get a job in the industry!
 
Share this answer
 
v2
Comments
miguel santos 2021 18-Sep-23 6:19am    
Private Sub btnSubmit_Click()

Application.ScreenUpdating = False

Dim Rows As Long
'data base table name and range
Rows = Folha("student_list").Range("A1048576").End(x1UP).Row + 1
'data base table name and total range

With EsteLivro.Folhas("student_list")
'insert fields

.Range("A" & Rows).Value = Rows + 9999 'this row will genetate and insert serial number
.Range("B" & Rows).Value = txtfirstname.Value
.Range("C" & Rows).Value = txtlastname.Value
.Range("D" & Rows).Value = txtemail.Value
.Range("E" & Rows).Value = txtphone.Value
.Range("F" & Rows).Value = cmbgender.Text
.Range("G" & Rows).Value = cmblevel.Text
.Range("H" & Rows).Value = cmbcountry.Text
.Range("I" & Rows).Value = cmbcity.Text
.Range("J" & Rows).Value = txtaddress.Value
.Range("K" & Rows).Value = txtcurrent_address.Value

Unload UserForm2

Application.ScreenUpdating = True
End With

End Sub
Dave Kreskowiak 18-Sep-23 8:16am    
You posting more unexplained code as a reply doesn't help the situation. You're not describing what the problem is!
miguel santos 2021 18-Sep-23 8:39am    
Quando eu executo o código, dá o erro:
Sub, Função ou Propriedade não definida.
não sei se srá de você meu excell estar em português e a semântica é diferente,
worksheet= Folha
ThisWorkSheet = EsteLivro etc, como disse estou a me inciar em vba.
Muito obrigado
OriginalGriff 18-Sep-23 9:05am    
Answer updated.
miguel santos 2021 18-Sep-23 6:20am    
rivate Sub btnSubmit_Click()

Application.ScreenUpdating = False

Dim Rows As Long
'data base table name and range
Rows = Folha("student_list").Range("A1048576").End(x1UP).Row + 1
'data base table name and total range

With EsteLivro.Folhas("student_list")
'insert fields

.Range("A" & Rows).Value = Rows + 9999 'this row will genetate and insert serial number
.Range("B" & Rows).Value = txtfirstname.Value
.Range("C" & Rows).Value = txtlastname.Value
.Range("D" & Rows).Value = txtemail.Value
.Range("E" & Rows).Value = txtphone.Value
.Range("F" & Rows).Value = cmbgender.Text
.Range("G" & Rows).Value = cmblevel.Text
.Range("H" & Rows).Value = cmbcountry.Text
.Range("I" & Rows).Value = cmbcity.Text
.Range("J" & Rows).Value = txtaddress.Value
.Range("K" & Rows).Value = txtcurrent_address.Value

Unload UserForm2

Application.ScreenUpdating = True
End With

End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900