Non databound column in a grid on a Form

  • Thread starter Thread starter BobRoyAce
  • Start date Start date
B

BobRoyAce

Let's say I have a form that shows data in a gridview. Further assume that
one or the columns in the grid is not data bound. What I want to do is, when
the user presses Enter while in the unbound column, or when they move off
the record, I want to interrogate the value in that column (for the record
they were on) and then insert a number of identical rows in the grid (at the
end) based on that number. For example, if they put a 2, I want to insert
two records identical to the one they were on when they entered 2. How could
I accomplish something like this?
 
You certainly could use the after update event of that un-bound text box.

I would probably make a right click menu, and use that instead. So, you
users could right click, and select "make copies". I world also consider the
use of a button.

However, you can use a un-bound text box, but I think it might confuse users
a bit, as they are not used that type of interface. You could even put a
button called "copy" on the form.

But, I see no reason why you can't use that un-bound text box idea if you so
wish.

The after update event of the text box would simply re-copy the current
record as many times as you need. You could use:

dim strSql as string
dim i as integer
dim intCopies as integer


intCopies = val(nz(me.txtCopy,"0"))

if intCopies > 0 then
me.txtCopy = null

strSql = "INSERT INTO tblName( Description, Catagory , main_id)" & _
" SELECT tblName Description, Catagory, " & me.Main_id & _
" FROM tblAnswers WHERE id = " & me.ID

me.dirty = false ' write current record to disk
for i = 1 to intCopies
currentdb.Execute strSql
next i

end if


Not much code. Note how I insert the foreign key into the select sql. Also,
note how you do NOT include the autonumber id, as that changes for each
record. Of course, you can extend the field list to include all the fields
you want. I also assumed that your sub-form is a child table. I also used
the un-bound text box name of txtCopy. You can re-name those to suite your
needs.

The above is air code as typed, so it likely not 100% correct, but it
certainly enough to give you the idea.
 
Back
Top