12 Replies - 1834 Views - Last Post: 18 December 2012 - 09:21 PM Rate Topic: -----

#1 mshayanshafi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-December 12

Unable to call public function in a form

Posted 14 December 2012 - 03:28 PM

I have got two forms in my program:
1.frm_itemlist
2.frm_supplier
I have declared a public function named Clear in frm_itemlist.This function works fine when I call it in frm_itemlist.The problem occurs when I try to call the function in frm_supplier. The function simply doesnt execute and neither do i get any errors. Here is the code for the function :
Public Sub Clear() 'will empty the all fields on the current form
    Dim a As Control    'variable declared for controls'
    For Each a In Controls  'found each control in the entire form'
        If TypeOf a Is TextBox Then 'if control is text then the value of the text will be set empty'
        a.Text = ""
        End If
    Next
End Sub


Here is the code I am using to call it in frm_supplier:
Private Sub cmd_ClearSupplier_Click()
Call frm_itemlist.Clear
End Sub


Please help me out. Thanks in advance.....

Is This A Good Question/Topic? 0
  • +

Replies To: Unable to call public function in a form

#2 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

Re: Unable to call public function in a form

Posted 14 December 2012 - 07:31 PM

do you get any errors when trying to run this code?
Was This Post Helpful? 0
  • +
  • -

#3 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,793
  • Joined: 26-March 09

Re: Unable to call public function in a form

Posted 15 December 2012 - 01:50 AM

When you say it doesn't execute, have you added a breakpoint within the function when you call it from the other form to confirm this?

Basically I'm asking, is it not executing at all, or is it executing and not behaving how you expect?
Was This Post Helpful? 0
  • +
  • -

#4 mshayanshafi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-December 12

Re: Unable to call public function in a form

Posted 15 December 2012 - 05:20 AM

View PostNeku, on 14 December 2012 - 07:31 PM, said:

do you get any errors when trying to run this code?

No errors whatsoever....

View Postmaj3091, on 15 December 2012 - 01:50 AM, said:

When you say it doesn't execute, have you added a breakpoint within the function when you call it from the other form to confirm this?

Basically I'm asking, is it not executing at all, or is it executing and not behaving how you expect?

Its not executing at all.When i click cmd_ClearSupplier all the text boxes in the form should go blank but nothing happens.Seems like the button has got no coding in it.....:(
Was This Post Helpful? 0
  • +
  • -

#5 olibenu  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 45
  • View blog
  • Posts: 538
  • Joined: 31-December 08

Re: Unable to call public function in a form

Posted 15 December 2012 - 05:49 AM

put a breakpoint on the line
For Each a In Controls


if the program doesn't break there, it means Clear() is not being called at all then you'll know your problem is something else
Was This Post Helpful? 0
  • +
  • -

#6 mshayanshafi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-December 12

Re: Unable to call public function in a form

Posted 15 December 2012 - 05:51 AM

And when I put a breakpoint in the fuction it tells me its executing but i cant see the outcome on the form....
Was This Post Helpful? 0
  • +
  • -

#7 olibenu  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 45
  • View blog
  • Posts: 538
  • Joined: 31-December 08

Re: Unable to call public function in a form

Posted 15 December 2012 - 06:02 AM

put in some breadcrumbs.

turn
a.Text = ""
to something else like

a.Text = "xyz"
and see if it does what it is supposed to do
Was This Post Helpful? 0
  • +
  • -

#8 mshayanshafi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-December 12

Re: Unable to call public function in a form

Posted 15 December 2012 - 06:31 AM

still nothing.....its executing but still not doing anything....
Its executing fine in frm_itemlist.....Its when i try to call it from frm_itemlist it creates a problem.....

*It creates a problem when I run it from frm_supplier
Was This Post Helpful? 0
  • +
  • -

#9 olibenu  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 45
  • View blog
  • Posts: 538
  • Joined: 31-December 08

Re: Unable to call public function in a form

Posted 15 December 2012 - 06:40 AM

if the code is running but it is not doing what you want. the next question to ask yourself is this:

what is the code doing?

it's being a while i used vb6 but shouldn't *Controls in the loop* be assigned to something? like frm_name.controls or something like that?

hint: check how many times that loop iterates.

This post has been edited by olibenu: 15 December 2012 - 06:54 AM

Was This Post Helpful? 1
  • +
  • -

#10 mshayanshafi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-December 12

Re: Unable to call public function in a form

Posted 15 December 2012 - 10:26 AM

View Postolibenu, on 15 December 2012 - 06:40 AM, said:

if the code is running but it is not doing what you want. the next question to ask yourself is this:

what is the code doing?

it's being a while i used vb6 but shouldn't *Controls in the loop* be assigned to something? like frm_name.controls or something like that?

hint: check how many times that loop iterates.


Problem solved.....Previously,when I pressed the clear button it did not take Controls as frm_supplier.Controls....I rewrote the function something like this....
Public Sub Clear(frm_name As Form) 'will empty the all fields on the form specified
       Dim a As Control
       For Each a In frm_name.Controls  'find each control in the specified form'
        If TypeOf a Is TextBox Then 'if the control is textbox then the value of the text will be set empty'
        a.Text = ""
        End If
       Next
End Sub


And called it like this in frm_supplier.....
Private Sub cmd_ClearSupplier_Click()
Call frm_itemlist.Clear(frm_supplier)
End Sub


I am an amateur so I made the careless mistake.Thanks a million for your help......
Btw just one last query
Whats the problem in this code.....I am getting an error that says Invalid use of Property
Dim frm_name as Form
frm_name=frm_supplier 


Was This Post Helpful? 0
  • +
  • -

#11 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Unable to call public function in a form

Posted 16 December 2012 - 10:30 PM

Quote

Whats the problem in this code.....I am getting an error that says Invalid use of Property
Dim frm_name as Form
frm_name=frm_supplier 



Use Set frm_name = frm_supplier.

This post has been edited by BobRodes: 16 December 2012 - 10:30 PM

Was This Post Helpful? 1
  • +
  • -

#12 mshayanshafi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-December 12

Re: Unable to call public function in a form

Posted 17 December 2012 - 05:58 AM

Ok....thanks....:D
Was This Post Helpful? 0
  • +
  • -

#13 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Unable to call public function in a form

Posted 18 December 2012 - 09:21 PM

You're welcome. In VB6, if you are working with a variable that is actually a reference to an object (as your form variables are), then you have to use the Set keyword when you are assigning it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1