473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

VB5 and DAO 3.6 Creating a DB and fields...

I am trying to create a database programmatically using vb5 with the DAO 3.6
object. I'm using the following segment, but I'm not having any luck. I
can't seen to find much help either. Any offerings here?

Set db = CreateDatabase(dbFileName, dbLangGeneral, dbVersion30)
db.Execute "CREATE TABLE Food_Table (Category Text(50), " & _
"Name Memo NOT NULL, " & _
"SoldState Text(50), " & _
"Packaging Memo , " & _
"Ingredients Memo, " & _
"Description Memo, " & _
"Instructions Memo, " & _
"ShelfDays Integer, " & _
"SuggestedSides Memo, " & _
"SuggestedWines Memo)"
Set tdfTableDef = db.CreateTableDef("Food_Table")
Set fldField = tdfTableDef.Fields("Category")
fldField.AllowZeroLength = True ' I'm doing this because I cant to
allow a zero length field
tdfTableDef.Fields.Append fldField
Debug.Print tdfTableDef.Fields.Count
db.Close
Jul 17 '05 #1
3 8426
On Sun, 3 Jul 2005 22:44:37 -0400, "Jon Smyth" <jo*@smyth.com> wrote:
I am trying to create a database programmatically using vb5 with the DAO 3.6
object. I'm using the following segment, but I'm not having any luck. I
can't seen to find much help either. Any offerings here?
Greetings. I find it "better" to use the long form in creating
databases instead of an SQL statement. That way you get better error
reporting and debugging.

Dim db As Database, tbd As TableDef

Set db = OpenDatabase(LocalDB)

Set tbd = db.CreateTableDef("ProductMaster")
AddNewField tbd, "PartNumber", 55&, dbText, False, True
AddNewField tbd, "Description", 100&, dbText, True, False
db.TableDefs.Append tbd

Public Sub AddNewField(tbd As TableDef, ByVal FieldName, _
ByVal FieldSize As Long, ByVal FieldType, AZL As Boolean, _
Required As Boolean)

Dim fld As Field

If FieldSize > 0 Then
Set fld = tbd.CreateField(FieldName, FieldType, FieldSize)
fld.AllowZeroLength = AZL
Else
Set fld = tbd.CreateField(FieldName, FieldType)
End If

fld.Required = Required
tbd.Fields.Append fld
Set fld = Nothing
End Sub
Set db = CreateDatabase(dbFileName, dbLangGeneral, dbVersion30)
db.Execute "CREATE TABLE Food_Table (Category Text(50), " & _
"Name Memo NOT NULL, " & _
"SoldState Text(50), " & _
"Packaging Memo , " & _
"Ingredients Memo, " & _
"Description Memo, " & _
"Instructions Memo, " & _
"ShelfDays Integer, " & _
"SuggestedSides Memo, " & _
"SuggestedWines Memo)"
Set tdfTableDef = db.CreateTableDef("Food_Table")
Set fldField = tdfTableDef.Fields("Category")
fldField.AllowZeroLength = True ' I'm doing this because I cant to
allow a zero length field
tdfTableDef.Fields.Append fldField
Debug.Print tdfTableDef.Fields.Count
db.Close


Jul 17 '05 #2
Thanks! That did the trick!

"David Rice, Esq." <de*********@hottmail.com> wrote in message
news:42**************@news.aioe.org...
On Sun, 3 Jul 2005 22:44:37 -0400, "Jon Smyth" <jo*@smyth.com> wrote:
I am trying to create a database programmatically using vb5 with the DAO 3.6object. I'm using the following segment, but I'm not having any luck. I
can't seen to find much help either. Any offerings here?


Greetings. I find it "better" to use the long form in creating
databases instead of an SQL statement. That way you get better error
reporting and debugging.

Dim db As Database, tbd As TableDef

Set db = OpenDatabase(LocalDB)

Set tbd = db.CreateTableDef("ProductMaster")
AddNewField tbd, "PartNumber", 55&, dbText, False, True
AddNewField tbd, "Description", 100&, dbText, True, False
db.TableDefs.Append tbd

Public Sub AddNewField(tbd As TableDef, ByVal FieldName, _
ByVal FieldSize As Long, ByVal FieldType, AZL As Boolean, _
Required As Boolean)

Dim fld As Field

If FieldSize > 0 Then
Set fld = tbd.CreateField(FieldName, FieldType, FieldSize)
fld.AllowZeroLength = AZL
Else
Set fld = tbd.CreateField(FieldName, FieldType)
End If

fld.Required = Required
tbd.Fields.Append fld
Set fld = Nothing
End Sub
Set db = CreateDatabase(dbFileName, dbLangGeneral, dbVersion30)
db.Execute "CREATE TABLE Food_Table (Category Text(50), " & _
"Name Memo NOT NULL, " & _
"SoldState Text(50), " & _
"Packaging Memo , " & _
"Ingredients Memo, " & _
"Description Memo, " & _
"Instructions Memo, " & _
"ShelfDays Integer, " & _
"SuggestedSides Memo, " & _
"SuggestedWines Memo)"
Set tdfTableDef = db.CreateTableDef("Food_Table")
Set fldField = tdfTableDef.Fields("Category")
fldField.AllowZeroLength = True ' I'm doing this because I cant to
allow a zero length field
tdfTableDef.Fields.Append fldField
Debug.Print tdfTableDef.Fields.Count
db.Close

Jul 17 '05 #3
On Mon, 4 Jul 2005 07:20:17 -0400, "Jon Smyth" <jo*@smyth.com> wrote:
Thanks! That did the trick!


I love Usenet. :-)

Jul 17 '05 #4

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

Similar topics

1
by: Don Stefani | last post by:
Hello, I have a form that I want to submit "onchange", OK I've got that working, but when the form submits, I want to pass along a value to a CGI script, as if that value was in a hidden form...
6
by: NotGiven | last post by:
I want to learn moer of what I saw in a recent example. They create a page that created new fields/element. It's not like they were hidden and they displayed them, they were not there, then the...
8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
4
by: Ronnie | last post by:
Ok let me just say first that I am a newbie in Access and I don't know much of SQL or VB programming. But I am trying to create this contact database using Access 97. I have created 2 tables,...
1
by: Dixie | last post by:
I wish to add some fields to an existing table in code. I am using the following code from rkc. CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25") This works , but I need to also set...
4
by: Martin | last post by:
I want to build a data entry form for creating and updating info on something. When I'm first creating an item all the fields need to be editable. There after some fields become readonly. Most...
5
by: Kaspa | last post by:
I am creating a contact database and I would like the user to create his own groups of contacts based on criterias, thefore I would like to let him pick the fields and criteria for a particular...
0
by: lianaent | last post by:
Hi All, I'm brand new to asp.net 2.0, and have a simple task of just creating a quick and dirty data entry form with SQL Server 2005 on the back end. I added a gridview to my form, and I can...
2
by: adwest | last post by:
Forgive me if this is a foolish question. I "play" in Access and have only created a few rather simple relational databases. My knowledge and experience is limited. I have no formal training, just...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.