Solved Error on Creating a Query after changing LongTextField to Short Text (1 Viewer)

silentwolf

Active member
Local time
Today, 03:49
Joined
Jun 12, 2009
Messages
575
Hi guys,
could not find proper help from the net and maybe some of you guys know what the issue could be and if there is a way to go about it.

Via VBA I am importing CSV Files into my system and for that mater I need a LongText "Memo" field

However I am updating that field via code .. cleaning up that field of not needet Text.

Because of the reduced field size and for further Update queries I would need that field in a Textfield.

So I use following code

Code:
Public Sub UpdateFieldSizeToShort(tableName As String)
    With CurrentDb
        .Execute "ALTER TABLE " & tableName & " ALTER COLUMN Umsatztext TEXT(255)", dbFailOnError
    End With
End Sub

All works no errors all good..
But as soon as I create a simple SELECT Query I get that following error

Due to a Value that you placed into a Table Property An invalid condition was detected by Access....

if I click on it or away the Query runs as ment.

There are no FK or any of that ..
The string length of the original data was maximum 300 caracters in length or even less..

It is not critical for me as I can transfer the Table into a new Table but would like to know if any of you guys may have a solution as it would be nicer
to continue with that table rather then create a new one or move Data into a new table.

Cheers
 

tvanstiphout

Active member
Local time
Today, 03:49
Joined
Jan 22, 2016
Messages
225
I have never tried this, but if the field had >255 chars in some records, this statement might not actually have executed as well as you think.

One idea is to create a new field, copy the Left(255) in it using an Update query, delete the old field, and rename the new field.
 

silentwolf

Active member
Local time
Today, 03:49
Joined
Jun 12, 2009
Messages
575
Hi,
I just checked the "LongText" field for the Data and all went in correctly..

Not exactly sure why it does that but as I mentioned it is not the end of the world so I just need to see which option is best suited.

Cheers anyway )
 

cheekybuddha

AWF VIP
Local time
Today, 11:49
Joined
Jul 21, 2014
Messages
2,284
I think your SQL is wrong.

Try instead:
Code:
Public Sub UpdateFieldSizeToShort(tableName As String)
    With CurrentDb
        .Execute "ALTER TABLE " & tableName & " ALTER COLUMN Umsatztext VARCHAR(255)", dbFailOnError
    End With
End Sub
 

silentwolf

Active member
Local time
Today, 03:49
Joined
Jun 12, 2009
Messages
575
Hi David,

I tried your code but unfortunatelly that does not change it..

Same issue

Cheers
 

ebs17

Well-known member
Local time
Today, 12:49
Joined
Feb 7, 2020
Messages
1,949
Code:
    With CurrentDb
        .Execute "UPDATE " & tableName & " SET Umsatztext = Left(Umsatztext, 255)", dbFailOnError
        .Execute "ALTER TABLE " & tableName & " ALTER COLUMN Umsatztext TEXT(255)", dbFailOnError
    End With
I would first change the content before changing the data type.
 

Josef P.

Well-known member
Local time
Today, 12:49
Joined
Feb 2, 2023
Messages
827
During the conversion, the TextFormat property remains, which Short Text cannot do anything with.
=>
Code:
With CurrentDb
    .Execute "UPDATE " & tableName & " SET Umsatztext = Left(Umsatztext, 255)", dbFailOnError
    .Execute "ALTER TABLE " & tableName & " ALTER COLUMN Umsatztext TEXT(255)", dbFailOnError
    .TableDefs(tableName).Fields("Umsatztext").Properties.Delete "TextFormat"
End With
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:49
Joined
May 7, 2009
Messages
19,247
create a new table with same structure but with short text rather than long text on the new table.
append the record from the old table to the new and delete the old.
rename the new table as the old table.
 

silentwolf

Active member
Local time
Today, 03:49
Joined
Jun 12, 2009
Messages
575
Hi arnelgp,

yes that is what I done now and it works just fine.

Cheers Guys :)
 

Users who are viewing this thread

Top Bottom