Re: VBA to Add or Remove a Field From a Table?
- From: "Terry Kreft" <terry.kreft@xxxxxxxxx>
- Date: Tue, 15 Nov 2005 13:51:46 -0000
The method you quoted is still valid. The reason I don't like it is because
it has an inherent danger in that it is too easy to setwarnings to false and
then forget to switch it back on. This then means that a whole bunch of
rather important warnings are switched off.
Try this for an example:-
create a table
fill it with some records
open the immediate window
type docmd.SetWarnings False and hit the enter key
switch to the database window
select your table
press the delete key.
Goodbye table and the associated records without any warning or chance to
back out of it.
--
Terry Kreft
"Br@dley" <brad@xxxxxxxxxx> wrote in message
news:AY9ef.17749$Hj2.362@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Terry Kreft wrote:
<SNIP>
>
>> BTW The SQL you quote can be executed as a one liner
>>
>> currentdb.Execute "DELETE * FROM tblMyTable WHERE [MyField] = 123"
>>
>> No need for that Setwarnings stuff.
>
>
> Sure. I just quoted one, perhaps older, method.
>
>>
>> "Br@dley" <brad@xxxxxxxxxx> wrote in message
>> news:z97ef.17471$Hj2.7897@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>>> No Spam wrote:
>>>> Dear Access 2003 users,
>>>>
>>>> Can anyone assist me with creating either code (preferred) or a
>>>> query that would remove a single field (called ID) from a table?
>>>
>>> This is pretty basic SQL.....
>>>
>>> DELETE * FROM tblMyTable WHERE [MyField] = 123;
>>>
>>> One method of running it from code:
>>>
>>> Function DeleteCode(ByVal pMyCode as Long)
>>> DoCmd.SetWarnings False
>>> DoCmd.RunSQL "DELETE * FROM tblMyTable WHERE [MyField] = " &
>>> pMyCode & ";"
>>> DoCmd.SetWarnings True
>>> Exit Function
>>>
>>> Oh hang on... or do you want to remove the actual field not just the
>>> data???
>>>
>>> Why?
>>>
>>> Hint: look up the TableDef object in the Access help.
>>>
>>>> And as a
>>>> bonus question, can anyone assist with adding a field (called ID)
>>>> to a table and then make it an Autonumber data type?
>>>> I've been successful
>>>> in adding the field via code,
>>>
>>> Code?
>>>
>>>> but cannot make it an autonumber field.
>>>> Thanks a million in advance!
>>>>
>>>> Kevin
>>>
>>> Please explain the scenario... ie. why are you trying to do this in
>>> code? --
>>> regards,
>>>
>>> Bradley
>>>
>>> A Christian Response
>>> http://www.pastornet.net.au/response
>
> --
> regards,
>
> Bradley
>
> A Christian Response
> http://www.pastornet.net.au/response
>
.
- References:
- VBA to Add or Remove a Field From a Table?
- From: No Spam
- Re: VBA to Add or Remove a Field From a Table?
- From: Terry Kreft
- Re: VBA to Add or Remove a Field From a Table?
- From: Br@dley
- VBA to Add or Remove a Field From a Table?
- Prev by Date: Re: Building SQL query when table is two words...
- Next by Date: Re: Report Driving Me Crazy!!
- Previous by thread: Re: VBA to Add or Remove a Field From a Table?
- Next by thread: Re: VBA to Add or Remove a Field From a Table?
- Index(es):
Relevant Pages
|