Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   saving input data in MS Access (http://www.go4expert.com/forums/saving-input-data-ms-access-t21235/)

viv345 7Mar2010 13:09

saving input data in MS Access
 
1 Attachment(s)
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

shabbir 7Mar2010 18:24

Re: saving input data in MS Access
 
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.

virxen 8Mar2010 02:04

Re: saving input data in MS Access
 
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 11Mar2010 18:41

Re: saving move around data in MS Access
 
1 Attachment(s)
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.

viv345 11Mar2010 18:43

Re: saving move around data in MS Access
 
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 14Mar2010 11:56

Re: saving input data in MS Access
 
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 15Mar2010 13:59

Re: saving input data in MS Access
 
1 Attachment(s)
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.

viv345 16Mar2010 16:25

Re: saving input data in MS Access
 
Thanks

viv345 16Mar2010 18:14

Re: saving input data in MS Access
 
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 16Mar2010 19:29

Re: saving input data in MS Access
 
Quote:

Originally Posted by viv345 (Post 65752)
Thanks

You could have used http://www.go4expert.com/images/buttons/post_thanks.gif button instead.


All times are GMT +5.5. The time now is 00:22.