Data-Access with Vbasic

Reply

Join Date: Jul 2007
Posts: 23
Reputation: elanch is an unknown quantity at this point 
Solved Threads: 0
elanch elanch is offline Offline
Newbie Poster

Data-Access with Vbasic

 
0
  #1
Jul 31st, 2007
hi friends!
I'm new to both vb and dataAccess. Now i have created a form in data-access. I need the datas entered in the form to be appended in the access-Table when i click the save button.

For eg:
Roll NO : Txt box
Name : Txt box
Sex : Txt box
Class : Txt box

New_Button Save_button

Here whenever i cllick the new_button all tha above fields to be re-set except the roll No. It has to display the next Roll No.(For eg. The previous roll No saved is 02ME11, Now it has to display 02ME12).
Then when i click the save_button, the datas has to be saved in access table.

please send me the code for this

elanch
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 95
Reputation: manoshailu is an unknown quantity at this point 
Solved Threads: 9
manoshailu's Avatar
manoshailu manoshailu is offline Offline
Junior Poster in Training

Re: Data-Access with Vbasic

 
0
  #2
Jul 31st, 2007
hi,

Use the below codings.


' To create an object for connection and recordset

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset


'To Create a New Id

Private Sub cmbnew_Click()
rs.Open "SELECT Mid([rollno],5,6) + 1 FROM Table1", cn, adOpenDynamic, adLockOptimistic
Text1.Text = "02ME" + Trim(Str(rs(0)))
rs.Close
End Sub


'To Add records

Private Sub cmdadd_Click()
rs.Open "select * from table1", cn, adOpenDynamic, adLockOptimistic
rs.AddNew
rs(0) = Text1.Text
rs(1) = Text2.Text
rs(2) = Text3.Text
rs(3) = Text4.Text
rs.Update
rs.Close
End Sub


'To Set connections.

Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open "dani", False, False
End Sub


Regards
Shailu
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Data-Access with Vbasic

 
0
  #3
Jul 31st, 2007
HI Mona,


I think we should use Max():

rs.Open "SELECT Max(Mid([rollno],5,6)) + 1 FROM Table1", cn, adOpenDynamic, adLockOptimistic


And we may get Error if there are no recs in the Table, check for Null there

Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 95
Reputation: manoshailu is an unknown quantity at this point 
Solved Threads: 9
manoshailu's Avatar
manoshailu manoshailu is offline Offline
Junior Poster in Training

Re: Data-Access with Vbasic

 
0
  #4
Aug 1st, 2007
hi veena,


U r right veena i forget to include that max.


regards
shailu.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 2
Reputation: dedort is an unknown quantity at this point 
Solved Threads: 0
dedort dedort is offline Offline
Newbie Poster

Re: Data-Access with Vbasic

 
0
  #5
Aug 2nd, 2007
hi friends!
I'm new to vb and access. i would like to ask favor from you on how to connect my database access to vb? cause i have difficulties in coding my connection from access to vb.
thnaks!
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 95
Reputation: manoshailu is an unknown quantity at this point 
Solved Threads: 9
manoshailu's Avatar
manoshailu manoshailu is offline Offline
Junior Poster in Training

Re: Data-Access with Vbasic

 
0
  #6
Aug 2nd, 2007
hi,

use below code.

'Create an object for connection and recordset
'set reference
'Project -> Reference - > Microsoft Activex Data Objects 2.6 Library

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Form_Load()

'Set Connections and recordset

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset

'Create DSN by
'In Run Command type "odbcad32" and press enter
'Then in userDSN tab click ADD button, select "Microsoft Access Driver(*.mdb), type any name in Data Source Name, click the Database button,Select access Database where u stored.
use that DSN name in connection open. Here i used DSN name "dani"

cn.Open "dani", False, False
End Sub


regards.
shailu.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC