Help with ADO-Access, please [RESOLVED]
I'm newbie with ADO. Probably too conservative with VB5 methods (now I'm using VB6), I was using DAO till rencently.
I have a problem (I think a stupid and simple problem): if I'm creating a new record, I can't avoid this to be saved in the database. It is, I can't cancel.
Example: I'm filling data in a form, I decide not to add it to the base, but any action I do updates the base with the data.
I'm linking the form objects with the recordset fields and ending the cmdNew_Click() sub with rsXXXX.AddNew.
Thanks
Re: Help with ADO-Access, please
Can you post some code? Are you using the ADO Data control? There are events that you can add to trap the before
updating event and cancel it out.
Re: Help with ADO-Access, please
Well, I have a "New" command button to add records a database. I'm using all code, not using the ADO Data control.
VB Code:
Private sub cmdNew_Click()
txtTitle.Text = ""
txtAutor.Text = ""
txtPub.Visible = False
cmbPubs.Visible = True
rsBooks.AddNew
end sub
I've resolved the problem by making enable=true in all of the other command buttons (navigation and delete, edit, save and close, all coded), but it's an artifficial solution and not a real solution.
Thanks for the answer, and sorry for my english.
Re: Help with ADO-Access, please
I believe that is not an artificial solution as you said because you really have to prevent users from doing anything else except save or cancel (not movenext, movefirst, etc.....) when you are adding a new record....
Anyway there is the .CancelUpdate that you could use to cancel the addition of the previously saved record..... I havent got the chance to use it anymore because mostly now I am using action queries (Insert Into, Update, Delete) in my data manipulation....
Re: Help with ADO-Access, please
.AddNew should be used in your app in a way that they click Add command button and that clears the textboxes, etc.
Then after they fill in all the controls with data, they click an "Update" command button. This is where you place your .AddNew along
with setting the fields data with their correcponding controls data and then do the .Update. You can have a "Cancel Update" command
button too. That would do the .CancelUpdate method previously posted.
Ps, I'm glad to see that your not using bound controls. ;)
Re: Help with ADO-Access, please
This maybe RobDog888 is suggesting....
VB Code:
Private Sub Add()
textbox1 = vbNullString
textbox2 = vbNullString
....
textbox1.SetFocus
End Sub
Private Sub Save()
AdoRecordset.AddNew
AdoRecordset.Fields("Field1").Value = textbox1
AdoRecordset.Fields("Field1").Value = textbox1
.....
AdoRecordset.Update
End Sub
Re: Help with ADO-Access, please
Thanks. I can't believe wht silly errors I'm doing. The dee-u solution is what I was using in DAO. Maybe I was too confused but ADO in programmings terms are not so different to DAO that I was thinking.
Thanks a lot.
RobDog888: I never use the bound controls. I alwasy want to control my code ;)
Re: Help with ADO-Access, please
Cool! Dee-u got it correct. Yes, DAO and ADO are very similar but ADO is better when your connecting to Access from another program.
Re: Help with ADO-Access, please
Thanks, so I modify the title of this tread as [Resolved] :thumb: