Help with coding

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to add two buttons to a data input form: Delete and Create New.

Of course, adding them is the easy part. Creating working functions for them
is another matter totally. What I want the Delete button to do is delete the
current record that's being viewed, not the entire table, or column etc. The
Create New button should move the user past all the filled up fields and
records and bring him to a blank set of records. Kind of like the Create New
button on the Navigation Bar works.

So, any ideas on how to do this?
 
This is the easier way. Use the wizard to put a button that delete current
record on the form. Same story to add record.
If you want to control by yourself you need to use ADO. Using the event "on
click" for the delete butto the code should look like:
Sub Procedure button1_OnClick()
Dim StrSql as String
StrSql = "DELETE ID FROM Table1 WHERE (((ID)=" & Me.ID &"));
currentDB.Execute StrSql
end sub

Hope this is useful!
 
kory said:
This is the easier way. Use the wizard to put a button that delete current
record on the form. Same story to add record.

Good advice. OP, if the wizard is "on" when you drop the button onto
your form, you get a choice of predefined buttons, including "delete
record" & "add record".

If you want to control by yourself you need to use ADO. Using the event "on
click" for the delete butto the code should look like:
Sub Procedure button1_OnClick()
Dim StrSql as String
StrSql = "DELETE ID FROM Table1 WHERE (((ID)=" & Me.ID &"));
currentDB.Execute StrSql
end sub

That's DAO (Data Access Objects), not ADO. Note also, you can have
problems if you delete records "behind the scenes" like that. Best to
requery the form (Me.Requery), after the deletion.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
Back
Top