Background:
Front end- MS Visual Studio/Visual Basic 2017
Back end- MS SQL Server 2016
I have two forms (Form1 and Form2). I know how to have Form2 pass data back to Form1. Can I have Form2 execute some code (specifically a sub routine) in Form1?
Thanks in advance.
3 1500 Frinavale 9,735
Recognized Expert Moderator Expert
Yes, make the function in Form1 public (or Friend) so that it can be accessed in Form2 .
If you cannot make this function Shared ( static in C#) then you will also have to provide a means to set a reference to Form1 in Form2 .
You can do this by: - Providing a constructor in
Form2 that takes an instance of Form1 so that it can save a reference to it - Implementing a Public (or Friend) method in
Form2 that sets a reference to Form1 - Implementing a Public (or Friend) property in
Form2 that allows Form1 set a reference to itself
Thanks. It works except the subroutine in form 1 has code in it to load a data grid view. -
Dim qry As String = "select recd_id, recd_number, recd_inventorydate from t021400_records order by recd_number desc;"
-
Dim cs As String = "SERVER=techdev01;DATABASE=DB02_RECORD_MANAGEMENT;USER ID=db02;PASSWORD=db02;"
-
Try
-
Dim connectionString As String = cs
-
Dim connection As New SqlConnection(connectionString)
-
Dim dataadapter As New SqlDataAdapter(qry, connection)
-
Dim ds As New DataSet()
-
connection.Open()
-
dataadapter.Fill(ds, "dgv")
-
' dataadapter.Fill(ds)
-
connection.Close()
-
dgv_Records.DataSource = DBNull.Value
-
dgv_Records.DataSource = ds
-
dgv_Records.DataMember = "dgv"
-
-
-
With dgv_Records
-
.RowsDefaultCellStyle.BackColor = Color.Bisque
-
.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige
-
End With
-
-
-
Catch EX As Exception
-
MsgBox(EX.ToString & " - (Error)")
-
Exit Sub
-
End Try
-
The dgv_records (the datagridview) get an error "Cannot refer to an instance member of a class from within a shared member or shared member initializer without an explicit instance of the class." Any ideas?
Frinavale 9,735
Recognized Expert Moderator Expert
Shared/Static methods cannot use anything that is not also Shared/Static (or will be created and destroyed within the method)
Your dgv_Records DataGridView cannot be a static/shared item because it is tied to the instances of the form.
Either remove the shared modifier from the method or think of another way to refresh your grid (IE raise an event that the form listens for or something)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Brian K. |
last post by:
I am trying to split up and secure a database that we've been using on
a network for a few years, following the procedure listed in Q304932
from microsoft.
I create a new blank database for the front end, and am able to import
tables and link from the backend. Queries come in ok too. When I
tried to import Modules, forms, and reports, most of them failed with
the error: "File Not Found:...
|
by: Gaurav |
last post by:
Hi,
We are developing a .NET app which has forms authentication. When the
user types in the direct URL of an aspx page on the browser, he will
be thrown to the login page. But if the URL points to a .txt or .doc
file, the document is displayed even though the user is not
authenticated.
How do we stop this such that the user has to login to the application
and then view the documents.
|
by: Shahid Juma |
last post by:
Hi,
I tried using Request.Forms.Clear() but it says it is only a read-only
property.
I have a form and that same form has to be filled out 3 times and what
I am trying is to clear the values once it is filled and automaitcally
change the label and load the same form again to record.
Any ideas?
|
by: Mac Campbell |
last post by:
Is there a simple way to import all forms from another mdb into the currently open mdb? I have trouble getting the current code to "see" a "forms" object in the external mdb.
|
by: Phill W. |
last post by:
I'm trying to implement Drag-and-Drop within a TreeView.
Back in VB "Proper", I'd have use the Treeview's DropHighlight property
to give the user an indication of where they're about to drop whatever
it is they're dragging but all-grown-up, OO, Visual Basic's TreeView
doesn't /have/ this property any more.
How can/should I reproduce this behaviour these days?
BTW: I do /not/ want to use the TreeView's SelectedNode property.
| |
by: coolCoder |
last post by:
Hi,
I am working on an application which needs localization. I am
able to localize all the controls on the form except the tool tips. I
searched alot on google, but was unable to find some sample
application. Does anyone here have an idea for implementing
localization easily for tool tips in windows forms application ?
Another question is about the procedure to implement
localization in winforms application. I have built a class library...
|
by: Spin |
last post by:
Hi,
I keep getting a Windows Repair error report that pops up when I try to access any of my forms in one of my databases. In efforts to troubleshoot the problem I copied these forms into another database and was luckily able to access and even edit them. To clear possible file corruption problems I copied the rest of the objects I needed for the database like the queries, tables, etc into the new database, however after doing this the error...
|
by: raylopez99 |
last post by:
Keywords: scope resolution, passing classes between parent and child
forms, parameter constructor method, normal constructor, default
constructor, forward reference, sharing classes between forms.
Here is a newbie mistake that I found myself doing (as a newbie), and
that even a master programmer, the guru of this forum, Jon Skeet,
missed! (He knows this I'm sure, but just didn't think this was my
problem; LOL, I am needling him)
If...
|
by: ChrisJensen |
last post by:
Hello!
I'm currently trying to fill in a dialogue box (from an external program) using a VB.Net app. I've succeeded in finding the window handle for the external program (using the FindWindowByCaption function), but am having some difficulty finding the handles for the child windows (which, in this case, would be text boxes). Most tutorials that I've found online suggest using Spy ++ (or other programs) that I don't have access to on this...
|
by: Josh Argent |
last post by:
Okay, I want to make a php script that will be able to access and post a form on another website and return the result pages value.
For example, I want a user to be able to enter a password and username for facebook and then it will submit the login form and return their wall. Is this possible in php? I don't mind experimenting with any language. :D
Thanks in advance.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |