944,141 Members | Top Members by Rank

Ad:
Jul 31st, 2007
0

Data-Access with Vbasic

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elanch is offline Offline
23 posts
since Jul 2007
Jul 31st, 2007
0

Re: Data-Access with Vbasic

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
Reputation Points: 34
Solved Threads: 10
Junior Poster
manoshailu is offline Offline
105 posts
since Jun 2007
Jul 31st, 2007
0

Re: Data-Access with Vbasic

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
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Aug 1st, 2007
0

Re: Data-Access with Vbasic

hi veena,


U r right veena i forget to include that max.


regards
shailu.
Reputation Points: 34
Solved Threads: 10
Junior Poster
manoshailu is offline Offline
105 posts
since Jun 2007
Aug 2nd, 2007
0

Re: Data-Access with Vbasic

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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dedort is offline Offline
2 posts
since Aug 2007
Aug 2nd, 2007
0

Re: Data-Access with Vbasic

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.
Reputation Points: 34
Solved Threads: 10
Junior Poster
manoshailu is offline Offline
105 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: var or string value goes into another form
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: problem with report in notepad





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC