473,804 Members | 3,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set Unicode Compression in code

I am writing some vba to create a new field if it is not already there.
Code follows.

The code I have so far, creates the new field in the table and sets the
AllowZeroLength property = true.

'Start code
Private Sub AddNewField_Cli ck()

On Error GoTo ErrAddNewField_ Click
Dim db As DAO.Database
Dim fld As DAO.Field
Dim tdf As DAO.TableDef

Set db = Application.Cur rentDb
Set tdf = db.TableDefs("t blTestCode")
Set fld = tdf.CreateField ("MyNewField 1", dbText, 150)

With fld
.AllowZeroLengt h = True
End With

With tdf.Fields
.Append fld
.Refresh
End With

Set fld = Nothing
Set tdf = Nothing
Set db = Nothing

Exit Sub

ErrAddNewField_ Click:
MsgBox Err.Description
Resume Exit_ErrAddNewF ield_Click

End Sub
'End code

I have two problems.

1. How do I create this new field ONLY if it does not already exist.
2. This code defaults to Unicode Compression = No for a text field and I
would like it to be Yes. How do I do this?

dixie
Nov 13 '05 #1
2 6289
> I have two problems.

1. How do I create this new field ONLY if it does not already exist.
2. This code defaults to Unicode Compression = No for a text field and I would like it to be Yes. How do I do this?

dixie


Just two? Consider yourself lucky!

1. you check to see if the field exists... I got the TableExists code
from Accessweb and then wrote the FieldExists function by tweaking
that... The debug statements are just so you can see where the
"search" fails - whether the table or the field doesn't exist.

'************** ****** Code Start *************** *********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
'
Function fExistTable(str TableName As String) As Boolean
Dim db As Database
Dim i As Integer
Set db = DBEngine.Worksp aces(0).Databas es(0)
fExistTable = False
db.TableDefs.Re fresh
For i = 0 To db.TableDefs.Co unt - 1
If strTableName = db.TableDefs(i) .Name Then
'Table Exists
fExistTable = True
Exit For
End If
Next i
Debug.Print "Table exists: " & fExistTable
Set db = Nothing
End Function
'************** ****** Code End *************** *********

Function fExistField(str TableName As String, strFieldName As String) As
Boolean
On Error GoTo ErrHandler

Dim db As Database
Dim tdf As TableDef
Dim i As Integer

If fExistTable(str TableName) = True Then
Set db = DBEngine.Worksp aces(0).Databas es(0)
Set tdf = db.TableDefs(st rTableName)

For i = 0 To tdf.Fields.Coun t
If strFieldName = tdf.Fields(i).N ame Then
'Field Exists
fExistField = True
Exit For
End If
Next i

Set tdf = Nothing
Set db = Nothing
Else
fExistField = False
End If
Debug.Print "Field exists: " & fExistField

Exit Function

ErrHandler:
If Err.Number = 3265 Then
Debug.Print "Field exists: " & fExistField
fExistField = False
Err.Clear
End If

End Function

Nov 13 '05 #2
Its a lot of code for such a teensy weensy thing :>)

Actually, I already use the If Exists table form of the code in other areas.

If I just put On Error Resume Next at the top of the sub, would that not
work just as well? Because if the field already exists, it will create an
error? It appears to work, but I know it is not good practice and perhaps
there is a down side I cannot see.

Any help with number 2 - setting the Unicode Compression = Yes. I don't
really think it is that important, but I am told all text fields should be
set that way.

dixie

<pi********@hot mail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I have two problems.

1. How do I create this new field ONLY if it does not already exist.
2. This code defaults to Unicode Compression = No for a text field

and I
would like it to be Yes. How do I do this?

dixie


Just two? Consider yourself lucky!

1. you check to see if the field exists... I got the TableExists code
from Accessweb and then wrote the FieldExists function by tweaking
that... The debug statements are just so you can see where the
"search" fails - whether the table or the field doesn't exist.

'************** ****** Code Start *************** *********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
'
Function fExistTable(str TableName As String) As Boolean
Dim db As Database
Dim i As Integer
Set db = DBEngine.Worksp aces(0).Databas es(0)
fExistTable = False
db.TableDefs.Re fresh
For i = 0 To db.TableDefs.Co unt - 1
If strTableName = db.TableDefs(i) .Name Then
'Table Exists
fExistTable = True
Exit For
End If
Next i
Debug.Print "Table exists: " & fExistTable
Set db = Nothing
End Function
'************** ****** Code End *************** *********

Function fExistField(str TableName As String, strFieldName As String) As
Boolean
On Error GoTo ErrHandler

Dim db As Database
Dim tdf As TableDef
Dim i As Integer

If fExistTable(str TableName) = True Then
Set db = DBEngine.Worksp aces(0).Databas es(0)
Set tdf = db.TableDefs(st rTableName)

For i = 0 To tdf.Fields.Coun t
If strFieldName = tdf.Fields(i).N ame Then
'Field Exists
fExistField = True
Exit For
End If
Next i

Set tdf = Nothing
Set db = Nothing
Else
fExistField = False
End If
Debug.Print "Field exists: " & fExistField

Exit Function

ErrHandler:
If Err.Number = 3265 Then
Debug.Print "Field exists: " & fExistField
fExistField = False
Err.Clear
End If

End Function

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6362
by: JJ | last post by:
Hi, usually, I'm not using MS servers, but I have a big problem with a Access table. I should create a web application for a Historical Dipartment. They have create a populated a Access database using unicode compression field (for ancient language). I would like to export this table into MySQL o Postgres, but it's
5
4526
by: Bill Grigg | last post by:
I am attempting to set the UnicodeCompression property via code. The following line "appears" to work: tdf.Fields("State").Properties("UnicodeCompression").Value = True I can see the boolean in the property sheet change from No to Yes. However, the behavior has not changed at all. It still behaves as though it were set to No. When I change the boolean in the property sheet GUI it behaves as expected. Any thoughts?
4
3187
by: JJ | last post by:
Hi, usually, I'm not using MS servers, but I have a big problem with a Access table. I should create a web application for a Historical Dipartment. They have created a populated a Access database using unicode compression field (for ancient language). I would like to export this table into MySQL o Postgres, but it's
2
30262
by: deko | last post by:
Is it best practice to set Unicode Compression to "No" for memo fields in a table? What about text fields? According to the VB help entry: "Data in a Memo field is not compressed unless it requires 4,096 bytes or less of storage space after compression. As a result, the contents of a Memo field might be compressed in one record, but might not be compressed in another record."
4
6079
by: Bob Sillett | last post by:
This is one of those issues that doesn't clearly fit into a single category as it's both a C# and a database (mySql) issue. I want to INSERT and SELECT text in UTF8 from a C# application to mySql. My database character set is UTF8. I am using the native .NET provider from mysql.com. Everything is at the current version. My C# code for INSERT looks like this:
0
2331
by: jazaret | last post by:
I've been having a hard time getting the benefits that Unicode Compression offers (2003 Access). I've got a test database that I'd like to set the Unicode Compression for the fields. For this test I've got a simple table with 16 text fields with size 255 each. Now I'd like to modify the UC property in code. One of them with DAO like so... Set db = CurrentDb() Set tdef = db.TableDefs("Testtable")
18
620
by: Chameleon | last post by:
I am trying to #define this: #ifdef UNICODE_STRINGS #define UC16 L typedef wstring String; #else #define UC16 typedef string String; #endif ....
232
13383
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
20
2939
by: chance | last post by:
Hello, I want to add compression to a memory stream and save it in an Oracle database. This is the code I have so far: //save the Word document to a binary field, MemoryStream dataStream = new MemoryStream(); doc.Save(dataStream, SaveFormat.Doc); //now compress it GZipStream compressedZipStream = new GZipStream(dataStream,
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10303
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10070
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5508
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2978
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.