Access databases and VB

Moderators: Gogi
Number of threads: 767
Number of posts: 1599

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Delete a field from table if null using VB Posted by timread on 9 May 2007 at 3:23 AM
I'm trying to populate a table from append queries, howver I need to delete a column/field if it is null. I've tried to mix IIf and Fields.Delete in the event but VB doesn't like this:-

IIf ([IrRelatImport].[IRAttrib],null, Fields.Delete [IrRelatImport].[IRAttrib],)

Any help greatly appreciated
Report
Re: Delete a field from table if null using VB Posted by dokken2 on 9 May 2007 at 5:08 AM
: I'm trying to populate a table from append queries, howver I need to
: delete a column/field if it is null. I've tried to mix IIf and
: Fields.Delete in the event but VB doesn't like this:-
:
: IIf ([IrRelatImport].[IRAttrib],null, Fields.Delete
: [IrRelatImport].[IRAttrib],)
:
: Any help greatly appreciated
:

don't fully understand your question. will all records have the field as null? if you want to delete the field from the table, with ADO you could execute a sql DDL command-

ALTER TABLE table1 DROP column NewFld

there's probably a way to do the same with DAO or by using Jet.
Report
Re: Delete a field from table if null using VB Posted by timread on 9 May 2007 at 5:49 AM
Thanks for that, I only need that statement to run when the column in question is null. So how do I get that element in? e.g This is along the lines of what I thought would work:

DoCmd.RunSQL "Alter Table IRRelatImport DROP COLUMN IRAttrImpID WHERE IRAttrImpID is null"

But vb doesn't seem to like WHERE
Report
Re: Delete a field from table if null using VB Posted by dokken2 on 22 May 2007 at 11:53 AM
: Thanks for that, I only need that statement to run when the column
: in question is null. So how do I get that element in? e.g This is
: along the lines of what I thought would work:
:
: DoCmd.RunSQL "Alter Table IRRelatImport DROP COLUMN IRAttrImpID
: WHERE IRAttrImpID is null"
:
: But vb doesn't seem to like WHERE
:

dropping the column is an all or nothing deal, don't recall you can use WHERE to test if its null. one idea, use ado/dao to loop thru all the records in the table and count how many are null in that field. if the count matches total of records, the entire column is null so then perform the docmd.runsql



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.