Link to home
Start Free TrialLog in
Avatar of greg222
greg222

asked on

Easy Database Access

I am trying to send data to access, as well as edit and delete it.

I used the Visual Data Manager and created a DB called yob with two fields named "Name" and "Date".

I added the data control and connected to my form with two text boxes: txtName and txtDate.

I connected to the database with the data control and set the data Field for txtName and txtDate correctly.

I added command buttons for Add, Delete, Change and Search.

******THE QUESTION*******

Here is the code for the add button

Private Sub cmdAdd_Click()
 Form1.Data1.Recordset.AddNew
End Sub

I get this error:

Error - "Action was cancelled by an associated object" Error - 3426

- How can I Fix this error? I am simply looking for a way to add new record to the database.

- Also, how can I code the delete and edit buttons?


thanks
ASKER CERTIFIED SOLUTION
Avatar of Sairam_S
Sairam_S

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of greg222
greg222

ASKER

i tried that. I can only add two records, then the last record is overwritten
Avatar of greg222

ASKER

It will not work. Here is the code so far:



Private Sub cmdAdd_Click()

 If Not (datMain.Recordset.BOF Or datMain.Recordset.EOF) Then
          datMain.Recordset.MoveLast
          datMain.Recordset.MoveNext
        End If


If datMain.Recordset.EOF Or datMain.Recordset.BOF Then
               
              MsgBox "true" 'debug
             
              Dim strBuffer As String, strBuff2 As String

              ' Save what was typed into the text box into memory
              strBuffer = txtInvNum.Text
              strBuff2 = txtDes.Text
             
              ' Restore text box value to the original record contents
              ' in this case, that is NULL
              datMain.UpdateControls

              ' Add a new blank record
              datMain.Recordset.AddNew

              ' Restore what has been typed from memory to text box
              txtInvNum.Text = strBuffer
              txtDes.Text = strBuff2
             
              ' Save the current record we are on and Add a new blank
              ' record
              datMain.Recordset.AddNew
              'datMain.Recordset.MoveLast
             
              txtInvNum.Text = ""
              txtDes.Text = ""
              datMain.Recordset.AddNew

Else
              MsgBox "else" ' debug
             
              'datMain.Recordset.MoveLast
              datMain.Recordset.AddNew
              txtInvNum.Text = ""
              txtDes.Text = ""
End If

End Sub


I just want to add new records, but this is not working.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial