473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Unable to reference form field...

I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates.txtJobNo.Text

I am getting the following error when I debug the line to see what the value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad
Jun 27 '08 #1
9 2880
On Jun 3, 6:52*pm, "Brad Pears" <br...@truenorthloghomes.comwrote:
I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates.txtJobNo.Text

I am getting the following error when I debug the line to see what the value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad
Without seeing your full code, i found that suggestion which may work
for you:
http://www.velocityreviews.com/forum...ed-member.html

Thanks,

Onur Güzel
Jun 27 '08 #2
Unfortunately that solution appears to be specific to ASP... I will jsut use
a public variable for now but I'd like to get to the bottom of that issue...

Thanks for the response...

Brad

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:55**********************************@p25g2000 hsf.googlegroups.com...
On Jun 3, 6:52 pm, "Brad Pears" <br...@truenorthloghomes.comwrote:
I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates.txtJobNo.Text

I am getting the following error when I debug the line to see what the
value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad
Without seeing your full code, i found that suggestion which may work
for you:
http://www.velocityreviews.com/forum...ed-member.html

Thanks,

Onur Güzel
Jun 27 '08 #3
On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
<br***@truenorthloghomes.comwrote:
>I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates.txtJobNo.Text

I am getting the following error when I debug the line to see what the value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad
If frmSteelPlates is a reference to the other form, and if txtJobNo is
marked Public, then it would work.

My guess is that frmSteelPlates is a class name, not a reference to an
instance of the class.

I don't think it is good practice to make controls be Public and
reference them from somewhere else. It ties the code too closely to
how you chose to implement the form.

I would add to the form that contains the textbox a Public Function
that returns the value, something like:

Public Function GetJobNo() As String
Return txtJobNo.Text
End Function

Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number.
Jun 27 '08 #4
Ok, that sounds good. I will implement it like that instead. In teh meantime
I decided to use a public variable (pJobNo) which works fine, but I prefer
not to use them if there is a better method that is not too difficult of an
implementation.

Thanks, Brad

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:n4********************************@4ax.com...
On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
<br***@truenorthloghomes.comwrote:
>>I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates.txtJobNo.Text

I am getting the following error when I debug the line to see what the
value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad

If frmSteelPlates is a reference to the other form, and if txtJobNo is
marked Public, then it would work.

My guess is that frmSteelPlates is a class name, not a reference to an
instance of the class.

I don't think it is good practice to make controls be Public and
reference them from somewhere else. It ties the code too closely to
how you chose to implement the form.

I would add to the form that contains the textbox a Public Function
that returns the value, something like:

Public Function GetJobNo() As String
Return txtJobNo.Text
End Function

Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number.

Jun 27 '08 #5
One other quick question...

When you said

" Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number."

I'm just not sure what you mean there...

Basically I want to call your function "GetJobNo" in a completely different
form (the one that calls the stored procedure) than the one that fucntion
"GetJobNo" was declared public in. I can't do that unless I pass the actual
entire form by reference to the new form - is that what you mean?

Could you give me a quick example of what you are referring to there?

Thanks, Brad

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:n4********************************@4ax.com...
On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
<br***@truenorthloghomes.comwrote:
>>I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates.txtJobNo.Text

I am getting the following error when I debug the line to see what the
value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad

If frmSteelPlates is a reference to the other form, and if txtJobNo is
marked Public, then it would work.

My guess is that frmSteelPlates is a class name, not a reference to an
instance of the class.

I don't think it is good practice to make controls be Public and
reference them from somewhere else. It ties the code too closely to
how you chose to implement the form.

I would add to the form that contains the textbox a Public Function
that returns the value, something like:

Public Function GetJobNo() As String
Return txtJobNo.Text
End Function

Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number.

Jun 27 '08 #6
Yes. You need a reference to the form that contains the textbox
(saying "pass the actual entire form by reference" doesn't really mean
anything, a reference is a pointer to the instantiation of the class).

You can get the reference in a couple of ways. If the form with the
textbox starts the other form, then it is easy. If the second form is
a modal dialog box then you will have code like:

Using frm2 As New Form2
frm2.ShowDialog()
End Using

To pass a reference to the calling form you can either pass it as a
parameter to the form's New or call a method:

Using frm2 As New Form2(Me)
or
Using frm2 As New Form2
frm2.SetCallingForm(Me)
frm2.ShowDialog()
End Using

You could also look through the application's list of forms to find
the form you want (System.Windows.Forms.Application.OpenForms).

On Tue, 3 Jun 2008 17:01:49 -0400, "Brad Pears"
<br***@truenorthloghomes.comwrote:
>One other quick question...

When you said

" Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number."

I'm just not sure what you mean there...

Basically I want to call your function "GetJobNo" in a completely different
form (the one that calls the stored procedure) than the one that fucntion
"GetJobNo" was declared public in. I can't do that unless I pass the actual
entire form by reference to the new form - is that what you mean?

Could you give me a quick example of what you are referring to there?

Thanks, Brad

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:n4********************************@4ax.com.. .
>On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
<br***@truenorthloghomes.comwrote:
>>>I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates.txtJobNo.Text

I am getting the following error when I debug the line to see what the
value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad

If frmSteelPlates is a reference to the other form, and if txtJobNo is
marked Public, then it would work.

My guess is that frmSteelPlates is a class name, not a reference to an
instance of the class.

I don't think it is good practice to make controls be Public and
reference them from somewhere else. It ties the code too closely to
how you chose to implement the form.

I would add to the form that contains the textbox a Public Function
that returns the value, something like:

Public Function GetJobNo() As String
Return txtJobNo.Text
End Function

Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number.
Jun 27 '08 #7
Brad,

A class is only a template, this is a little bit confusing for former VB6
users, as in that language where AFAIK classes always shared classes, and
therefore in fact modules.

The form class is now a real class. And therefore you have to instance it
from your current class to an obect.

Therefore as you show us how you have instanced frmSteelPlates, then some of
us can tell you probably more.

(There are and endles quantity of methods to create an form object)

Cor

"Brad Pears" <br***@truenorthloghomes.comschreef in bericht
news:eB**************@TK2MSFTNGP06.phx.gbl...
>I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates.txtJobNo.Text

I am getting the following error when I debug the line to see what the
value of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad
Jun 27 '08 #8
On Wed, 4 Jun 2008 05:40:36 +0200, "Cor Ligthert[MVP]"
<no************@planet.nlwrote:
>Brad,
Cor,
>A class is only a template, this is a little bit confusing for former VB6
users, as in that language where AFAIK classes always shared classes, and
therefore in fact modules.
In VB6, a class must be stored in a single file and a single file
cannot contain more than one class. Still, except for the lack
of inheritance, classes in VB6 work pretty much like those in
VB.Net, albeit a little crippled by comparison.

A default instance of a form in VB6 can be referenced without
instantiation, but it is also possible to create multiple, non-default
instances of a form.
>The form class is now a real class. And therefore you have to instance it
from your current class to an obect.
This was true in VS2002 and VS2003, but VS2005 (re)introduced
the default instance model known from VB6, so in VB.Net 2005+ it
is now possible to write

Sub main()
Form1.ShowDialog()
End Sub

i.e. display the default instance of a form without declaring
it first. This is (now) handled behind the scenes.

If all you ever need is to display one instance of the same
form class at a time, the default instance can be used.

My personal opinion is that Microsoft never should have
added the default instance stuff but kept forcing developers
to keep things explicit, i.e. out in plain view. Less opportunity
for errors and confusion.
>Therefore as you show us how you have instanced frmSteelPlates, then some of
us can tell you probably more.
I'll second that.

Regards,

Joergen Bech

Jun 27 '08 #9
Got it!!

I'm pretty new to this stuff...

Thanks, Brad

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:ep********************************@4ax.com...
Yes. You need a reference to the form that contains the textbox
(saying "pass the actual entire form by reference" doesn't really mean
anything, a reference is a pointer to the instantiation of the class).

You can get the reference in a couple of ways. If the form with the
textbox starts the other form, then it is easy. If the second form is
a modal dialog box then you will have code like:

Using frm2 As New Form2
frm2.ShowDialog()
End Using

To pass a reference to the calling form you can either pass it as a
parameter to the form's New or call a method:

Using frm2 As New Form2(Me)
or
Using frm2 As New Form2
frm2.SetCallingForm(Me)
frm2.ShowDialog()
End Using

You could also look through the application's list of forms to find
the form you want (System.Windows.Forms.Application.OpenForms).

On Tue, 3 Jun 2008 17:01:49 -0400, "Brad Pears"
<br***@truenorthloghomes.comwrote:
>>One other quick question...

When you said

" Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number."

I'm just not sure what you mean there...

Basically I want to call your function "GetJobNo" in a completely
different
form (the one that calls the stored procedure) than the one that fucntion
"GetJobNo" was declared public in. I can't do that unless I pass the
actual
entire form by reference to the new form - is that what you mean?

Could you give me a quick example of what you are referring to there?

Thanks, Brad

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:n4********************************@4ax.com. ..
>>On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
<br***@truenorthloghomes.comwrote:

I have the following code that references a "textbox" on a form. I want
to
pass the value of this textbox to a stored procedure as a parameter.
This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it
is
located on (class name) in front as follows...

param1 = frmSteelPlates.txtJobNo.Text

I am getting the following error when I debug the line to see what the
value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad
If frmSteelPlates is a reference to the other form, and if txtJobNo is
marked Public, then it would work.

My guess is that frmSteelPlates is a class name, not a reference to an
instance of the class.

I don't think it is good practice to make controls be Public and
reference them from somewhere else. It ties the code too closely to
how you chose to implement the form.

I would add to the form that contains the textbox a Public Function
that returns the value, something like:

Public Function GetJobNo() As String
Return txtJobNo.Text
End Function

Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number.

Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Terje Sæternes | last post by:
It seems that this script wont run, any idea what I have don wrong+ Code----- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title>...
5
by: Rose | last post by:
I want to use the javascript dom to reference the field of a record in a multi-record html form when that field has been changed. How do I reference the field? I have a JavaScript function coded...
1
by: ubmc | last post by:
Revised form layout by dragging/dropping fields from field list and deleting unwanted fields. However, unable to go to next existing record or return to previous existing record, but can add new...
3
by: hmiller | last post by:
I have created and IIF statement in an unbound text box. The IIF statement produces a text result, ie "On Time", in the unbound text box. What I would like to do is reffence this text box and then...
1
by: hrhoe | last post by:
Hi, I'm trying to create a reusable component with C#. So, I created a user control that uses Microsoft SQLDMO Object Library (SQLDMO). And I could add that UserControl on Toolbox. However,...
14
by: mchlle | last post by:
How can I filter records of a subform that is part of a tab control? The filter works fine on the form when it is not part of the tab using this in the macro condition: !!="Today" I have a main...
7
by: planetthoughtful | last post by:
Hi All, I have an app that presents a small main form when run. When a particular button is clicked, I'd like to briefly display another small form directly below the main form, regardless of...
2
by: Kanashii | last post by:
First off - I want to thank all who respond / try to help out and even those who took a moment to read over my question. Please be patient as I am -very- new to VB in general and unfortunately...
0
by: ll | last post by:
I'm working with 'pure ASP upload' script which is designed to redirect to an alert/error message, should a file larger than the set limit be attempted to be uploaded. The problem is that, while...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.