Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

sub or function not defined

Hi, :WAVE:
I am new to VB6 and prctically dont know anything about it. :confused:
After consulting some books i made a prog for employee management.
On clicking the Add New button for employee i get a compiler error saying sub or function not defined.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Command11_Click()
HideButtons
Data1.Recordset.AddNew
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Above given is the line it shows for the error.

Also it gives an error for the last portion of the code.The entire code is given .I gave spaces for names of labels but in that last part of code , i think it is giving an error because of that.

If anyone could give thier time and patience to it , I would be grateful.

Thanks
:D


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Private Sub OLE1_Updated(Code As Integer)

End Sub

Private Sub Command1_Click()
Mm.Show
End Sub

Private Sub File1_Click()

End Sub

Private Sub Command11_Click()
HideButtons
Data1.Recordset.AddNew
End Sub

Private Sub Command2_Click()
Data1.Recordset.MoveFirst
End Sub

Private Sub Command3_Click()
Data1.Recordset.MoveLast
End Sub

Private Sub Command4_Click()
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
MsgBox "You are on the first record"
Data1.Recordset.MovePrevious
End If
End Sub

Private Sub Command5_Click()
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
MsgBox "You are on the last record"
Data1.Recordset.MoveLast
End If
End Sub

Private Sub Dept_Click()

End Sub

Private Sub Command6_Click()
On Error Resume Next

Data1.Recordset.Delete
If Not Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
ElseIf Not Data1.Recordset.BOF Then
Data1.Recordset.MovePrevious
Else
MsgBox "This was the last record in the table"
End If
End Sub

Private Sub Command7_Click()
On Error GoTo CancelUpdate
Data1.Recordset.Update
ShowButtons
Exit Sub

CancelUpdate:
MsgBox Err.Description
Data1.Recordset.CancelUpdate
ShowButtons
End Sub

Private Sub Command8_Click()
Data1.Refresh
Data1.Recordset.FindFirst "Name='" & prevName & "'"
ShowButtons
End Sub

Sub ShowButtons()

AddBttn.Visible = True
DeleteBttn.Visible = True
OkBttn.Visible = False
CancelBttn.Visible = False

End Sub

Private Sub Data1_Error(DataErr As Integer, Response As Integer)
MsgBox Err.Description
Response = 0
Data1.Recordset.CancelUpdate
End Sub

###########################################################################
(ERROR PORTION)

Private Sub Data1_Validate(Action As Integer, Save As Integer)
Dim Reply

If txtStaffNo.DataChanged Or txtDeptCode.DataChanged Or _
txtSectionCode.DataChanged Or txtDesignation.DataChanged Or _
txtDateofLastPromotion.DataChanged Or txtDateofJoining.DataChanged Or _
txtName.DataChanged Or txtDateofJoin_Section.DataChanged Then
Reply = MsgBox("Record has been changed. Save?", vbYesNo)
If Reply = vbNo Then
Save = False
End If
End If
End Sub
###########################################################################
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[3754 byte] By [Manoz] at [2007-11-11 6:28:52]
# 1 Re: sub or function not defined
I don't see a Sub or Function named HideButtons?
Phil Weber at 2007-11-11 17:28:24 >
# 2 Re: sub or function not defined
i am sorry, i can't understand what u are trying to say. :confused:
I have copied certain sections from a book and that part is one of them.

Could you explain ?
Manoz at 2007-11-11 17:29:21 >
# 3 Re: sub or function not defined
You've copied the code, but not the properties. You need to rename your buttons (command1 should be cmdAdd for example).

This is why you shouldn't copy code from a book!
RHelliwell at 2007-11-11 17:30:30 >
# 4 Re: sub or function not defined
I don't get it. :confused:
First command1 is a button providing access to form for maintaining the database.

And if u meant command11 then it is named command11 in the properties for name :confused:

I have attached the file if u need it for reference.
Manoz at 2007-11-11 17:31:24 >
# 5 Re: sub or function not defined
In the book you copied the code from, in the first few pages before the code you'll most likely have a table of what to name each control.

You have for instance command1_click, but you're book probably tells you to rename command1 to cmdAdd, then when cmdAdd_click is called from another sub the code will actually work.

That's my theory anyway :)

P.S. I can't download .ZIP files at work, so i'll do it when I get home.
RHelliwell at 2007-11-11 17:32:34 >
# 6 Re: sub or function not defined
I am grateful to the amt of patience and attention you have given to my work. I am workin on your suggestion.

But could you tell me why tis portion is giving me an error.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Data1_Validate(Action As Integer, Save As Integer)
Dim Reply

If txtStaffNo.DataChanged Or txtDeptCode.DataChanged Or _
txtSectionCode.DataChanged Or txtDesignation.DataChanged Or _
txtDateofLastPromotion.DataChanged Or txtDateofJoining.DataChanged Or _
txtName.DataChanged Or txtDateofJoin_Section.DataChanged Then
Reply = MsgBox("Record has been changed. Save?", vbYesNo)
If Reply = vbNo Then
Save = False
End If
End If
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have given the names as Staff No(with a space) ,Dept Code and so on.
When i gave spaces in coding it said Syntax error. And now it gives some other error.Is it because of this statement or something else

Private Sub Data1_Validate(Action As Integer, Save As Integer

Your reply would be really helpful.
Manoz at 2007-11-11 17:33:33 >
# 7 Re: sub or function not defined
i have 1 question....
i am doing a proj subbmission using VB...which im not used to...

q1--can somebody please explainto me this, i dunt understand what is PageIndexChanged..dgFoodCat is the name of my datagrid.But wen i double clickthe datagrid i get selected_Index_Change...i dun understand??

q2--what does the line "dgFoodCat.CurrentPageIndex = e.NewPageIndex" means??

Private Sub dgFoodCat_PageIndexChanged(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
dgFoodCat.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
VBsuperNuts at 2007-11-11 17:34:28 >
# 8 Re: sub or function not defined
VBSuperNuts - Can you start your own thread please.

Manoz - add some breakpoints in your code to help pin point the code which is causing you problems.
RHelliwell at 2007-11-11 17:35:30 >