|
-
Nov 17th, 2009, 08:05 PM
#1
Thread Starter
Addicted Member
[RESOLVED] How to acces a Recordset from another form using the same connection
Hi Again,
Can some one help me with this. Iam trying to access a recordset on a main form from another form. For example if I have a recordset name RSCustomer and the connection is open I want to be able to perform a search from another form.
-
Nov 17th, 2009, 09:31 PM
#2
Lively Member
Re: How to acces a Recordset from another form using the same connection
declare as GLOBAL in general session can help?
GLOBAL RSCustomer as Recordset
-
Nov 17th, 2009, 09:42 PM
#3
Thread Starter
Addicted Member
Re: How to acces a Recordset from another form using the same connection
Thank you Vendoron for your response,
I try using the Global declaration but it wont work.
the the fallowing code is how Iam declaring my
variables. but even when I remove the Withevents I still get an error.
Code:
Option Explicit
Public WithEvents CustomerConn As ADODB.Connection
Public WithEvents rscustomer As ADODB.Recordset
Dim mblAddMode As Boolean
Last edited by Monti124; Nov 17th, 2009 at 09:46 PM.
-
Nov 18th, 2009, 03:41 AM
#4
Re: How to acces a Recordset from another form using the same connection
 Originally Posted by Monti124
Thank you Vendoron for your response,
I try using the Global declaration but it wont work.
the the fallowing code is how Iam declaring my
variables. but even when I remove the Withevents I still get an error.
Code:
Option Explicit
Public WithEvents CustomerConn As ADODB.Connection
Public WithEvents rscustomer As ADODB.Recordset
Dim mblAddMode As Boolean
What error...????
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 18th, 2009, 04:22 AM
#5
Re: How to acces a Recordset from another form using the same connection
And what code are you using in the other form?
In case you aren't aware, you must use the name of the form that the variables are declared in.
but even when I remove the Withevents I still get an error.
Based on that, it sounds to me like you don't understand what WithEvents is - and are therefore almost certainly not using it. If that is the case, you should remove it.
-
Nov 18th, 2009, 06:28 AM
#6
Re: How to acces a Recordset from another form using the same connection
 Originally Posted by Monti124
 Hi Again,
Can some one help me with this. Iam trying to access a recordset on a main form from another form. For example if I have a recordset name RSCustomer and the connection is open I want to be able to perform a search from another form.
One way is just to pass it to the other form Either the recordSet, Connection, or both)
Form1
Code:
Option Explicit
Private Sub Command1_Click()
Dim sConnString As String
Dim rsTemp As New ADODB.Recordset
Dim cnTest As New ADODB.Connection
Dim strSql As String
sConnString = "Server=DevSQL\TPA1;Database=Manhattan;Driver=SQL Server;Trusted_Connection=Yes"
With cnTest
.ConnectionString = sConnString
.ConnectionTimeout = 0
.CursorLocation = adUseClient
.Open
End With
strSql = "select top 1 * from Claim NoLOck"
rsTemp.Open strSql, cnTest, adOpenStatic, adLockReadOnly
Call Form2.DisplayForm(rsTemp)
End Sub
Form2
Code:
Option Explicit
Private rsForm2RecSet As New ADODB.Recordset
Private Sub Form_Load()
Label1.Caption = rsForm2RecSet.Fields("pkClaim")
End Sub
Public Sub DisplayForm(rsRecSet As ADODB.Recordset)
Set rsForm2RecSet = rsRecSet
Me.Show vbModal
End Sub
Notice DisplayForm is Public in Form2.
Last edited by TysonLPrice; Nov 18th, 2009 at 06:33 AM.
-
Nov 18th, 2009, 07:47 AM
#7
Fanatic Member
Re: How to acces a Recordset from another form using the same connection
I have recently asked a similar question about this, and was advised that when you use a form, and the form closes, all the local variables / connections etc are lost. You are best to declare the connections and recordsets (globally) in a module and call them in to the form from the module.
"Wisdom is only truly achieved, when you realise you dont know everything" ... I must be a genius because I always have to ask stupid questions...
Pointing an idiot like me in the right direction, is always appreciated by the idiot, explaining how to do what you have pointed the idiot to, is appreciated even more. I apologise to all experienced coders who will think I am an idiot, you are right, I am an idiot, but I am an idiot who is trying to learn
-
Nov 18th, 2009, 07:53 AM
#8
Re: How to acces a Recordset from another form using the same connection
 Originally Posted by vandoren
declare as GLOBAL in general session can help?
GLOBAL RSCustomer as Recordset
Public is the more current usage.
http://www.vbforums.com/showthread.php?t=461099
-
Nov 18th, 2009, 09:07 AM
#9
Thread Starter
Addicted Member
Re: How to acces a Recordset from another form using the same connection
Thank you all for you response,
I Finally got the code working.
Im not sure this is the Right way but is working.
What I did was declare a Second Recordset global in a module . Then I used this variable for the recordset to search my Data Base. when I got the result I plug that into the Datasource property of the first recordset.
Code:
Set RSsearch = New ADODB.Recordset
RSsearch.CursorType = adOpenStatic
RSsearch.CursorLocation = adUseClient
RSsearch.LockType = adLockPessimistic
RSsearch.Source = "SELECT * FROM [Customer] WHERE [City]='" & CVar(txtcity.Text) & "'"
RSsearch.ActiveConnection = CustomerConn
RSsearch.Open
Set Grid2.DataSource = RSsearch
Set RsCustomer.DataSource = RSsearch
Hope this will help others with same problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|