954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

using command button instead of datacontrol

hey i am new to visual basic programming...just 15-20 days into it...
i wanna know how can i use command button to access the ms access files instead of using the data control....how can i do that????
i have tried a lot of things but to no effect .... please help me with this!!!!
i tried to find this solution in the solved threads but without any success.

mayank_ati
Junior Poster in Training
97 posts since Jul 2007
Reputation Points: 38
Solved Threads: 0
 

Hi,

Add "Microsoft ActiveX objects 2.0" References to the project.
use this code:

Dim rs As New ADODB.Recordset
Dim AC As New ADODB.Connection
With AC
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDB.mdb;Persist Security Info=False"
.Open
End With
ssql = "Select * from MyTable"
Set rs=Nothing
RS.Open ssql,AC
If RS.EOF Then
  ' No Record Found
Else
  'Records Found
End If


Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

hey....
thanks for the code but on command click its not showing the records in the textboxes...
do i have to do anything...for that...likeways changing the properties..
thanks...

mayank_ati
Junior Poster in Training
97 posts since Jul 2007
Reputation Points: 38
Solved Threads: 0
 

Hi,

In continuation with above code:

If RS.EOF Then
' No Record Found
Else
text1.text = RS(0)
text2.text = RS(1)
text3.text = RS(2)
text4.text = RS(3)
text5.text = RS(4)
End If


Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

thanks !!!!
it worked.....

mayank_ati
Junior Poster in Training
97 posts since Jul 2007
Reputation Points: 38
Solved Threads: 0
 

what bout try yourself before ask for help and if possibel posting your code instead of asking for complete solution.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

i tried it my self quite a lot....
but just couldnt get the solution....
i know the rules .... sure dude....dont get angry...
i checked all the threads....but jus couldt get over..it....
i actully am a new programmer and dont kno much..
i just got as far as using a data control.....got it!

mayank_ati
Junior Poster in Training
97 posts since Jul 2007
Reputation Points: 38
Solved Threads: 0
 
hey i am new to visual basic programming...just 15-20 days into it... i wanna know how can i use command button to access the ms access files instead of using the data control....how can i do that???? i have tried a lot of things but to no effect .... please help me with this!!!! i tried to find this solution in the solved threads but without any success.


Why do you want to use the command button instead of a data control? Coz if you'll do that and then if you have another command you'll have to call/access again the database. the advantage of the data control is that you only ask the data control to display the data you wanted without "connecting again" to the database... just an opinion/thought hehehe, please don't get me wrong:$

jireh
Posting Whiz
316 posts since Jul 2007
Reputation Points: 11
Solved Threads: 49
 

thanx for your opinion....
but i guess data control has some limitations...
i may be wrong though.....
kindly guide me.....

mayank_ati
Junior Poster in Training
97 posts since Jul 2007
Reputation Points: 38
Solved Threads: 0
 
thanx for your opinion.... but i guess data control has some limitations... i may be wrong though..... kindly guide me.....


yeah! you cannot put them in modules hehehe I use controls than declaring variables to lessen the code so that it more readable. but of course I use variables too but only when needed. So how's your project now?
By the way are you using

Option Explicit


in your vb?

jireh
Posting Whiz
316 posts since Jul 2007
Reputation Points: 11
Solved Threads: 49
 

i'll show you my code but its all messed up right no........:(
but i have bought a black book on vb6.......:)
i'll contact you as soon as i get it in a better shape...
thanks for your concern:)

mayank_ati
Junior Poster in Training
97 posts since Jul 2007
Reputation Points: 38
Solved Threads: 0
 
i'll show you my code but its all messed up right no........:( but i have bought a black book on vb6.......:) i'll contact you as soon as i get it in a better shape... thanks for your concern:)


Have you tried the book of Diethel and Diethel? the're good, very friendly to the newbies...

jireh
Posting Whiz
316 posts since Jul 2007
Reputation Points: 11
Solved Threads: 49
 
adoRecordset.Open "select Project_Name,BU from Risk_Analysis", db2, adOpenStatic, adLockOptimistic

why am i gettin an error which says "object required" in this line

mayank_ati
Junior Poster in Training
97 posts since Jul 2007
Reputation Points: 38
Solved Threads: 0
 

Hi,

Check the following:

DB2 ADO Connection Object is open or not.
Declare RST
Dim RST As New ADODB.Recordset
Set RST=Nothing
RST.Open "select Project_Name,BU from Risk_Analysis", db2, adOpenStatic, adLockOptimistic

Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

what's the use of it???
i have no idea....

mayank_ati
Junior Poster in Training
97 posts since Jul 2007
Reputation Points: 38
Solved Threads: 0
 

hurray.....
i have completed the basic structure of my project...:P
thanx to all who have helpd me....
special thanks to jireh and qveen(veena)......

mayank_ati
Junior Poster in Training
97 posts since Jul 2007
Reputation Points: 38
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You