473,407 Members | 2,314 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,407 software developers and data experts.

property access from the form

Hi,

I have a form in a windows application. In that form I have declared the
public property InvoiceNo. I am trying to access this property from the
other form. In the other form I declared the first form as

public frmInvoice as InvoiceForm

after the declaration I have on load event in which I am trying to access
the property
Private Sub ReportViewer_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

dim inv as string

inv = frmInvoice.InvoiceNo
End Sub

I get the error of the Object reference not set to an instance of an object.
Now I can fix it by declaring

public frmInvoice as new InvoiceForm

but then I get frmInvoice.InvoiceNo as NOTHING

Please help

Apr 12 '06 #1
4 1114
Hi,

Try to conceptualise what you are trying to do, first.

A form is just an instance of a class, so we shouldn't treat it as if
it were something else.

Let us look at what you were trying to do, in order to understand the
problem :
(Assume that your ReportViewer Form is Class 2 and frmInvoice is Class
1)

1. Trying to access Class 1 from Class 2.
Problem : Class 1 has not been instantiated. No object has been
created.
Error : Null Reference exception.
Solution : Instantiate Class1. You did this by the statement "public
frmInvoice as new InvoiceForm()"

2. Trying to access the property "InvoiceNo" of Class 1 from Class 2.
Problem : Class 1 has been instantiated, but the property contains
Nothing. In short, you
are trying to access a property that has not been set.
Solution : Set a default value for the property in Class 1 code.

This solves the problem, but I don't think it is what you are trying to
do. Instead, I
believe you already have Class 1 (the InvoiceForm) running, and you
want to access it's
InvoiceNo property from Class 2 (the ReportViewer form).

This means that we must not initialize InvoiceForm again. We must
somehow get a reference to the already running InvoiceForm.

So, the question boils down to : "How to transfer the value of property
InvoiceNo in frmInvoice to ReportViewer". (Your original question was
"How to access the property InvoiceNo in frmInvoice from ReportViewer).
Can you see the difference ? You were thinking in the opposite
direction.

This can be solved simply by : (Assuming ReportViewer is loaded from
frmInvoice)
---------------------------------------------------
In frmInvoice:
---------------
Public Property InvoiceNo as Integer
:
:
End Property

'This procedure loads ReportViewer...
Private Sub LoadReport()
dim frm2 as New ReportViewer ()
frm2.myInvoiceNo = Me.InvoiceNo
frm2.show()
End Sub
In ReportViewer:
------------------
Friend myInvoiceNo as Integer
---------------------------------------------------
Hope this helps,

Regards,

Cerebrus.

Apr 12 '06 #2
Vivek,

What you have done with

"public frmInvoice as InvoiceForm"

Is creating a public placeholder for the adres of a to create object
frmInvoice

To instance it (to create a New object) you have to use the New word.
That can inside that declaration

\\\
public frimInfoice as New InvoiceForm
///

or otherwise as first statement in your load event.

\\\
frmInvoice = New InvoiceForm
///

Reading the message from Cerebrus again, I see that he writes in a way the
same, so see this as addition with some samples.

I hope this helps,

Cor
Cor

"Vivek Sharma" <vi*******@gmail.com> schreef in bericht
news:u7**************@TK2MSFTNGP03.phx.gbl...
Hi,

I have a form in a windows application. In that form I have declared the
public property InvoiceNo. I am trying to access this property from the
other form. In the other form I declared the first form as

public frmInvoice as InvoiceForm

after the declaration I have on load event in which I am trying to access
the property
Private Sub ReportViewer_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

dim inv as string

inv = frmInvoice.InvoiceNo
End Sub

I get the error of the Object reference not set to an instance of an
object.
Now I can fix it by declaring

public frmInvoice as new InvoiceForm

but then I get frmInvoice.InvoiceNo as NOTHING

Please help

Apr 12 '06 #3
Thanks Cerebrus. It is the best explaination ever.

Vivek

"Cerebrus" <zo*****@sify.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
Hi,

Try to conceptualise what you are trying to do, first.

A form is just an instance of a class, so we shouldn't treat it as if
it were something else.

Let us look at what you were trying to do, in order to understand the
problem :
(Assume that your ReportViewer Form is Class 2 and frmInvoice is Class
1)

1. Trying to access Class 1 from Class 2.
Problem : Class 1 has not been instantiated. No object has been
created.
Error : Null Reference exception.
Solution : Instantiate Class1. You did this by the statement "public
frmInvoice as new InvoiceForm()"

2. Trying to access the property "InvoiceNo" of Class 1 from Class 2.
Problem : Class 1 has been instantiated, but the property contains
Nothing. In short, you
are trying to access a property that has not been set.
Solution : Set a default value for the property in Class 1 code.

This solves the problem, but I don't think it is what you are trying to
do. Instead, I
believe you already have Class 1 (the InvoiceForm) running, and you
want to access it's
InvoiceNo property from Class 2 (the ReportViewer form).

This means that we must not initialize InvoiceForm again. We must
somehow get a reference to the already running InvoiceForm.

So, the question boils down to : "How to transfer the value of property
InvoiceNo in frmInvoice to ReportViewer". (Your original question was
"How to access the property InvoiceNo in frmInvoice from ReportViewer).
Can you see the difference ? You were thinking in the opposite
direction.

This can be solved simply by : (Assuming ReportViewer is loaded from
frmInvoice)
---------------------------------------------------
In frmInvoice:
---------------
Public Property InvoiceNo as Integer
:
:
End Property

'This procedure loads ReportViewer...
Private Sub LoadReport()
dim frm2 as New ReportViewer ()
frm2.myInvoiceNo = Me.InvoiceNo
frm2.show()
End Sub
In ReportViewer:
------------------
Friend myInvoiceNo as Integer
---------------------------------------------------
Hope this helps,

Regards,

Cerebrus.

Apr 12 '06 #4
You're most welcome. ;-)

Regards,

Cerebrus.

Apr 13 '06 #5

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

Similar topics

8
by: Vladimir | last post by:
Hello, I have a table in MS Access database. It has one field (with BYTE datatype) that has several properties set in Lookup tab of table Design View. Display Control = Combo Box. Row Source...
3
by: Mark | last post by:
Access97 --- I set the Required property for a field at the table level and I have a form that contains that field. When I click the Close button at the top left of the screen, I get an error...
1
by: Georg Scholz | last post by:
Hello, The class "Control" contains a documented Property "ControlType". So for example, in a form, you can write code like this: Dim c as control set c = me.Controls("textbox1") if...
1
by: tmaster | last post by:
Within a class, can I create a property that is a listview? Here's what I tried, but it doesn't seem to work: '------------ create property to give the second form access to the first form's...
4
by: Francis | last post by:
Hello i have a continuos form, and i have a command button to help insert information on a control textbox. But when the text box is not null, i dont want the command button to show (to the current...
8
by: AMDRIT | last post by:
Hello everyone, How do I access a property from another thread in VB'05? Thanks public class frmblah inherits system.windows.forms.form private mCount as integer private property Count...
15
by: Lauren Wilson | last post by:
Owning your ideas: An essential tool for freedom By Daniel Son Thinking about going into business? Have an idea that you think will change the world? What if you were told that there was no way...
8
by: Dean Slindee | last post by:
I have a form whose Property value I need to get at from a class (contained in another project, same solution). Here is the form's property: Private booIsInsert As Boolean = False Public...
0
by: iceborg | last post by:
Greetings, I have an application that was originally designed in Access 2000. It has been transformed to Access 2002 (XP), Access 2003, and now Access 2007. I have a form and subform, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.