Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
This is the code.
VB
Dim str As String
Private Sub submit_Click()
  str = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=hrms"
  Set con = New ADODB.Connection
  con.ConnectionString = str
  con.Open
  Set cmd = New ADODB.Command
  Set cmd.ActiveConnection = con
  cmd.CommandText = "sp_submit"
  cmd.CommandType = adCmdStoredProc
  cmd.Parameters.Append cmd.CreateParameter("@name", adVarChar, adParamInput, 25, RTrim(empname.Text))
  cmd.Parameters.Append cmd.CreateParameter("@address", adVarChar, adParamInput, 25, RTrim(address.Text))
  cmd.Parameters.Append cmd.CreateParameter("@email", adVarChar, adParamInput, 25, RTrim(email.Text))
  cmd.Execute
End Sub
Posted
Updated 19-Aug-12 23:37pm
v4
Comments
Martijn Kok 20-Aug-12 2:25am    
I have some assumptions to make because you don't supply much information about the error.

Is this VB from an Access application? I have seen this error there indicating that RTrim is an unknown function. If that is the case you might miss a reference to a DLL. Menu Extra -> Reference. In the list of references you might see a missing reference. Remove the refence an recreate it.

Not sure if this error might occure in Visual Basic 6.
Sergey Alexandrovich Kryukov 20-Aug-12 2:39am    
Any special reason to mess with VB6, ever?
--SA
abey e mathews 20-Aug-12 2:57am    
Client want vb6
Sergey Alexandrovich Kryukov 20-Aug-12 3:26am    
What?! Client? Do such client ever pay..? :-)
--SA
abey e mathews 20-Aug-12 4:12am    
Did you know?
if not dont comment

Declare the string inside sub

VB
Private Sub submit_Click()
Dim str As String
str = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=hrms"
Set con = New ADODB.Connection
con.ConnectionString = str
con.Open
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = con
cmd.CommandText = "sp_submit"
cmd.CommandType = adCmdStoredProc
cmd.Parameters.Append cmd.CreateParameter("@name", adVarChar, adParamInput, 25, RTrim(empname.Text))
cmd.Parameters.Append cmd.CreateParameter("@address", adVarChar, adParamInput, 25, RTrim(address.Text))
cmd.Parameters.Append cmd.CreateParameter("@email", adVarChar, adParamInput, 25, RTrim(email.Text))
cmd.Execute
End Sub
 
Share this answer
 
Comments
abey e mathews 20-Aug-12 2:57am    
i have use your code but the same error is happening
The eror "Sub or function not defined" happens when the compiler encounters a unknown method.

I have made a simple test with your code (with one minor adjustment because I needed to define a data source in de the connectionstring), and it executed as expected.

Next I added a fake method. And the "Sub or function not defined error ocured at the moment the compiler tried to compile the submit_Click sub. The code did break with the current line of executation (yellow) block on the submit_Click line. The unknown method had a darkblue background. You will probably see this as well. The blue marked method is the unknown method.

Next you'll need to know why the method is unknown. There shouldn't be any unknown methods in your code (as tested it worked ok). If you know which method is the unknown, you will need to ask yourself in which DLL this method is defined. In the menu goto Project -> Reference and check if the DLL is referenced by your project. If not add it and when you see the 'Missing Reference' message, unselect is, reopen the reference screen and add the reference again.

I hope this will help.
 
Share this answer
 

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