add new

S

short

In an unbound table, I have figured out how to delete a record and edit a
record with just pressing a command button and it will either allow the user
to edit the record or delete. I am having troubles with the add new.
This is my code: (the Add new in this code does not work)

'///////////////////////////////////////////
'This part checks to see if the Buttons (new, edit, or delete)
'are pressed in. If they are then it will
'make sure that you can edit, add or delete in the form.
'
'sets the "Add New" button to let additions in the form
'If tgAdd.value = True Then
' Addbool = True
'ElseIf tgAdd.value = False Then
' Addbool = False
'End If

'sets the "Edit" button to let Edits in the form
If tgEdit.value = True Then
Editbool = True
ElseIf tgEdit.value = False Then
Editbool = False
End If

'sets the "Delete" button to let Deletions in the form
If tgDelete.value = True Then
Deletebool = True
ElseIf tgDelete.value = False Then
Deletebool = False
End If

'///////////////////////////////////////////


Thanks.
 
M

Maarkr

did you leave the comments tick (') in your addnew code when you run it?
What is the code that runs the addbool value to add new records?
 
S

short

when I run it without the comments, when the button addnew is pressed nothing
happens, but if the Edit button is pressed (at the same time) then the table
opens a new record.
There is nothing in addbool, I'm working on someone elses database that left
and I have no idea what it is supposed to be used for.
 
K

Klatuu

You don't show the code where you are actually trying to update the values in
the table, so we can't tell from what you posted; however, what you are doing
is a really bad idea. Any time you are allowing the user to manipulate data,
it should be done through a form, not directly in a table.
 
S

short

There's another option to have another form open, when the user hits add new
that the person before me was working on. The only thing is, how could I
achieve that when there are about 24 tables that need to be worked on.
 
K

Klatuu

To make life simple, I have a template form that has all the navigation
buttons, search combo, and everything pretty much defined. I use this a lot,
because every application will have a lot of simple tables you just a form to
work with. When I need to make a form for one of these tables, I make a copy
of the template form, add a query based on the table as the form's record
source, and put some controls on the form for the fields in the table, make a
simple modification to the search combo to use the name of the table's
primary key and description fields, and now I have a form for that table. It
takes about 15 minutes.

The just open the form from the form you are in.
 
B

BruceM

As a bit of an aside, you can simplify code such as you have posted by using
something like:

Editbool = Me.tgEdit

That being said, you still should declare Editbool. From what you have
posted it is a Variant by default, since you have now showed it as being
declared otherwise. If you add the line:
Option Explict
at the top of the code module (just under Option Compare Database) then
undeclared variables will be caught when you compile the code.

If Editbool is a Boolean (Yes/No) variable, all you have done is to set it
to either yes or No (True or False). After it has a value something needs
to happen based on the value. As Dave pointed out, you are not showing any
updating of values in the posted code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top