By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,628 Members | 1,401 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,628 IT Pros & Developers. It's quick & easy.

Please help me soon

100+
P: 123
I have 2 forms in my project I am using vb. One form is sales and other is MainConn

I have written one function in MainConn form.

Expand|Select|Wrap|Line Numbers
  1. Dim ctl as control
  2. Public Sub Reset_Fields(ByVal frm As Form)
  3.     For Each objctl In frm.Controls
  4.         If UCase(TypeName(objctl)) = "TEXTBOX" Then
  5.                    objctl.Text = ""
  6.         End If
  7.     Next
  8. End Sub
I am calling this function from sales form by writting code:
frmMainConn.Reset_Fields(Me)

But above code doesnot work.
1) I am getting an error:Type mismatch.
2) When i type objctl in Reset_Fields function, pop up window doesnt come i.e. Text Property.

What is the solution? Can u tell me what is the correct code.Plz help me soon.
Mar 15 '07 #1
Share this Question
Share on Google+
5 Replies


100+
P: 1,646
Expand|Select|Wrap|Line Numbers
  1. Dim ctl as control
If the purpose of this declaration is only to have a control object for the sub then you should declare this object inside the sub
Expand|Select|Wrap|Line Numbers
  1. Public Sub Reset_Fields(ByVal frm As Form)
There is no need to have a form as a parameter because you are calling this sub from the same form therefore:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Reset_Fields()
will work unless you plan to use this code for other forms
Expand|Select|Wrap|Line Numbers
  1. For Each objctl In frm.Controls
We don't know where this object 'objctl' comes from. I assume you are putting together various pieces of code that you have picked up on TSDN from answers to your other questions which is why, from your point of view, getting others to write your code for you does not work. Having declared ctl, you should continue to use that in your sub
Expand|Select|Wrap|Line Numbers
  1. If UCase(TypeName(ctl)) = "TEXTBOX" Then
  2. ctl.Text = ""
  3. End If
So you can call this function like this:
Expand|Select|Wrap|Line Numbers
  1. Reset_Fields
You have posted enough here to understand that you must use code tags
Mar 15 '07 #2

100+
P: 123
Expand|Select|Wrap|Line Numbers
  1. Dim ctl as control
If the purpose of this declaration is only to have a control object for the sub then you should declare this object inside the sub
Expand|Select|Wrap|Line Numbers
  1. Public Sub Reset_Fields(ByVal frm As Form)
There is no need to have a form as a parameter because you are calling this sub from the same form therefore:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Reset_Fields()
will work unless you plan to use this code for other forms
Expand|Select|Wrap|Line Numbers
  1. For Each objctl In frm.Controls
We don't know where this object 'objctl' comes from. I assume you are putting together various pieces of code that you have picked up on TSDN from answers to your other questions which is why, from your point of view, getting others to write your code for you does not work. Having declared ctl, you should continue to use that in your sub
Expand|Select|Wrap|Line Numbers
  1. If UCase(TypeName(ctl)) = "TEXTBOX" Then
  2. ctl.Text = ""
  3. End If
So you can call this function like this:
Expand|Select|Wrap|Line Numbers
  1. Reset_Fields
You have posted enough here to understand that you must use code tags
No, I have declared the procedure, Reset_Fields in module. And i am calling this sub from other form. When I call the sub by Reset_Fields(Me) from other form, it gives an error that type mismatch. So how to call an object of the form?
Mar 16 '07 #3

100+
P: 1,646
Tell me about ctl and objctl
Mar 16 '07 #4

100+
P: 123
When you use 'Me' as a parameter you are sending a pointer to the form or, in visual basic language, a reference to the form. Therefore you must pass this parameter by reference or 'ByRef'. So change this:
Expand|Select|Wrap|Line Numbers
  1. Public Sub Reset_Fields(ByVal frmobj As Form)
to this:
Expand|Select|Wrap|Line Numbers
  1. Public Sub Reset_Fields(ByRef frmobj As Form)
Mar 16 '07 #5

100+
P: 1,646
When you use 'Me' as a parameter you are sending a pointer to the form or, in visual basic language, a reference to the form. Therefore you must pass this parameter by reference or 'ByRef'. So change this:
Expand|Select|Wrap|Line Numbers
  1. Public Sub Reset_Fields(ByVal frmobj As Form)
to this:
Expand|Select|Wrap|Line Numbers
  1. Public Sub Reset_Fields(ByRef frmobj As Form)
Sorry I edited your post by mistake instead of replying to it. Anyway the answer is there. Good luck
Mar 16 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.