Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: What am I missing?!

Geek News

What am I missing?!
miss031 11/14/2008 5:35:12 AM
I don't know why this won't work. I am getting a type mismatch error.


Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim varItem As Variant

Set db = CurrentDb

Set rst = db.OpenRecordset("tbl_firearms_licence")

For Each varItem In Me.txt_gun_lic_no.Column(0)

With rst
.AddNew
rst![contact_ID] = [Forms]![add_new_all]![contact_ID]
rst![licence_type] = varItem
'fill in here all the necessary field values
.Update

.Close
End With
Next varItem
RE: What am I missing?!
mscertified 11/14/2008 2:49:01 PM
ensure you are moving correct data type to each column (based on defined data
type in table design_). Also make sure no value has a NULL in it.

Also it looks like you are closing the recordset in the wrong place!

-Dorian

"miss031" wrote:

[Quoted Text]
> I don't know why this won't work. I am getting a type mismatch error.
>
>
> Dim db As DAO.Database
> Dim rst As DAO.Recordset
> Dim varItem As Variant
>
> Set db = CurrentDb
>
> Set rst = db.OpenRecordset("tbl_firearms_licence")
>
> For Each varItem In Me.txt_gun_lic_no.Column(0)
>
> With rst
> .AddNew
> rst![contact_ID] = [Forms]![add_new_all]![contact_ID]
> rst![licence_type] = varItem
> 'fill in here all the necessary field values
> .Update
>
> .Close
> End With
> Next varItem
RE: What am I missing?!
miss031 11/15/2008 6:05:01 AM
Thanks... sometimes a person just needs a fresh set of eyes. I changed the
code to below, but now, if there is 2 items selected in the listbox, it will
insert 2 records in the table, but they will both be the same, and the same
if there are 3 selected, it inserts 3 identical records. What did I screw up
now?


With rst
For Each varItem In Me.txt_gun_lic_no.ItemsSelected
.AddNew
rst![contact_ID] = [Forms]![add_new_all]![contact_ID]
rst![licence_type] = Me.txt_gun_lic_no.Column(0)
'fill in here all the necessary field values
.Update
Next varItem
.Close
End With

"mscertified" wrote:

[Quoted Text]
> ensure you are moving correct data type to each column (based on defined data
> type in table design_). Also make sure no value has a NULL in it.
>
> Also it looks like you are closing the recordset in the wrong place!
>
> -Dorian
>
> "miss031" wrote:
>
> > I don't know why this won't work. I am getting a type mismatch error.
> >
> >
> > Dim db As DAO.Database
> > Dim rst As DAO.Recordset
> > Dim varItem As Variant
> >
> > Set db = CurrentDb
> >
> > Set rst = db.OpenRecordset("tbl_firearms_licence")
> >
> > For Each varItem In Me.txt_gun_lic_no.Column(0)
> >
> > With rst
> > .AddNew
> > rst![contact_ID] = [Forms]![add_new_all]![contact_ID]
> > rst![licence_type] = varItem
> > 'fill in here all the necessary field values
> > .Update
> >
> > .Close
> > End With
> > Next varItem

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net