saving input data in MS Access

viv345's Avatar, Join Date: Feb 2010
Contributor
I am new bee in programming. i have created a Small program in VB & I want 2 save it in MS Access 2007. getting problem which is not recognized by me where i am doing wrong.
Hence i have attached my programme as project1.zip Pl tell me where giving wrong.
Thanks
Attached Files
File Type: zip Project1.zip (13.2 KB, 8 views)
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Please do not attach your code and ask to get it answered. I doubt you will do the same for others.

Explain what is not working and we would be more than happy to answer.
viv345 like this
virxen's Avatar, Join Date: Nov 2009
Pro contributor
try the changes below

Code:

Option Explicit
  Dim conn As New ADODB.Connection
  Dim cmdCommand As New ADODB.Command
  Dim rec As New ADODB.Recordset
Private Function connect()
  conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
    App.Path & "\" & "db1.mdb;Mode=Read|Write"
  conn.CursorLocation = adUseClient
  conn.Open
      cmdCommand.ActiveConnection = conn
      cmdCommand.CommandType = adCmdText
      rec.CursorType = adOpenDynamic
      rec.CursorLocation = adUseClient
      rec.LockType = adLockOptimistic
End Function

Private Sub Form_Load()
connect
End Sub

Private Sub Command1_Click()
cmdCommand.CommandText = "SELECT * FROM table1;"
rec.Open cmdCommand
rec.AddNew
rec.Fields(1) = Text1.Text
rec.Fields(2) = Text2.Text
rec.Fields(3) = Text3.Text
rec.Fields(4) = Text4.Text
     rec.Update
     'If Not rec.EOF Then rec.MoveNext
     MsgBox "record stored"
     rec.Close

End Sub

Private Sub Form_Unload(Cancel As Integer)
conn.Close
End Sub

Private Sub Text2_Click()
Form1.Text2.Text = Val(Form1.Text1.Text) * 1#
End Sub

Private Sub Text3_Click()
Form1.Text3.Text = Val(Form1.Text1.Text)
End Sub
Private Sub Text4_Click()
Form1.Text4.Text = Val(Form1.Text2.Text)
End Sub
viv345 like this
viv345's Avatar, Join Date: Feb 2010
Contributor
In my previous Project i have add some new commands like Next; Previous and Delete.
How I can code to move around my saved data.
Attached Files
File Type: zip Project1.zip (13.7 KB, 3 views)
viv345's Avatar, Join Date: Feb 2010
Contributor
In my previous Project i have add some new commands like Next; Previous and Delete.
How I can code to move around my saved data. i am getting problem. When click on next, Highlights Private Sub Command2_Click () and on End Sub, is this wrong.
Pl Help
viv345's Avatar, Join Date: Feb 2010
Contributor
THANKS

Can data saved in access remain constant after quitting the programme. and if delete/clear button is clicked how i can delete data in access
virxen's Avatar, Join Date: Nov 2009
Pro contributor
i have made some changes in your code.

1) code for deleting records (delete button)
2) code for next,previous (considering error situations,with appropriate messages)
3) button NEW added (press this to empty text boxes,add data and press save to store in DB)
4) label showing current record out of how many records

and many more.

check the code.

for more questions post again.
Attached Files
File Type: rar Project1.rar (12.5 KB, 6 views)
viv345 like this
viv345's Avatar, Join Date: Feb 2010
Contributor
Thanks
viv345's Avatar, Join Date: Feb 2010
Contributor
I want know one more thing that if their are more forms in a project viz., Form 1, Form2 etc etc then what will be the coding.
AND
In this project on this command it is giving error
Run-time error '3704'
Operation is not allowed when the object is closed


Private Sub Command8_Click() 'save button
rec.AddNew
rec.Fields(1) = Text1.Text
rec.Fields(2) = Text2.Text
rec.Fields(3) = Text3.Text
rec.Fields(4) = Text12.Text
rec.Fields(5) = Text13.Text
rec.Update
MsgBox "record stored"
currentRecord = currentRecord + 1
Label3.Caption = "Record " + CStr(currentRecord) + " of " + CStr(rec.RecordCount)

End Sub
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by viv345 View Post
Thanks
You could have used button instead.
viv345 like this