473,467 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

create fields

On the control of my form i want to give a command for creating fields
in a table.However i receive the message error variable not defined.
May i have some help as to where is my error?
Dim dbs As Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim prp As DAO.Property
Dim idx As DAO.Index

Set tdf = dbs.TableDefs("Orders")
Set fld = tdf.CreateField("LastUpdated", dbDate)
tdf.Fields.Append fld
tdf.Fields.Refresh

' set additional field properties
Set fld = tdf.Fields("LastUpdated")
fld.Properties("DefaultValue") = "=Date()"
Set prp = fld.CreateProperty("Format", dbText, "Short Date")
fld.Properties.Append prp

' create and append index
Set idx = tdf.CreateIndex("LastUpdatedIdx")
idx.Fields.Append idx.CreateField("LastUpdated")
idx.Unique = False
tdf.Indexes.Append idx

dbs.Close
Set prp = Nothing
Set idx = Nothing
Set fld = Nothing
Set tdf = Nothing
Set dbs = Nothing
End Function

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
3 10356
Svelte,
I think you forgot to 'set' your dbs ... like Set dbs=CurrentDb
Also: Why Dim all vars as DAO exept dbs?
Hence: Dim dbs As DAO.Database

--
Hope this helps
Arno R

"Svelte Poshy" <sv******@yahoo.com> schreef in bericht news:3f*********************@news.frii.net...
On the control of my form i want to give a command for creating fields
in a table.However i receive the message error variable not defined.
May i have some help as to where is my error?
Dim dbs As Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim prp As DAO.Property
Dim idx As DAO.Index

Set tdf = dbs.TableDefs("Orders")
Set fld = tdf.CreateField("LastUpdated", dbDate)
tdf.Fields.Append fld
tdf.Fields.Refresh

' set additional field properties
Set fld = tdf.Fields("LastUpdated")
fld.Properties("DefaultValue") = "=Date()"
Set prp = fld.CreateProperty("Format", dbText, "Short Date")
fld.Properties.Append prp

' create and append index
Set idx = tdf.CreateIndex("LastUpdatedIdx")
idx.Fields.Append idx.CreateField("LastUpdated")
idx.Unique = False
tdf.Indexes.Append idx

dbs.Close
Set prp = Nothing
Set idx = Nothing
Set fld = Nothing
Set tdf = Nothing
Set dbs = Nothing
End Function

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #2
Did you flag a line (f9) and then step through the code (f8)? Which
line did it stop on?

Svelte Poshy <sv******@yahoo.com> wrote in message news:<3f*********************@news.frii.net>...
On the control of my form i want to give a command for creating fields
in a table.However i receive the message error variable not defined.
May i have some help as to where is my error?
Dim dbs As Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim prp As DAO.Property
Dim idx As DAO.Index

Set tdf = dbs.TableDefs("Orders")
Set fld = tdf.CreateField("LastUpdated", dbDate)
tdf.Fields.Append fld
tdf.Fields.Refresh

' set additional field properties
Set fld = tdf.Fields("LastUpdated")
fld.Properties("DefaultValue") = "=Date()"
Set prp = fld.CreateProperty("Format", dbText, "Short Date")
fld.Properties.Append prp

' create and append index
Set idx = tdf.CreateIndex("LastUpdatedIdx")
idx.Fields.Append idx.CreateField("LastUpdated")
idx.Unique = False
tdf.Indexes.Append idx

dbs.Close
Set prp = Nothing
Set idx = Nothing
Set fld = Nothing
Set tdf = Nothing
Set dbs = Nothing
End Function

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #3
Arno R previously wrote:
Why Dim all vars as DAO exept dbs


Because it's not an ambiguous declaration.
So DAO. is unnecessary.
Regards
Peter Russell
Nov 12 '05 #4

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

Similar topics

2
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
4
by: Melissa | last post by:
I have a frontend file named CustomerApp and backend file named CustomerData. CustomerApp is at C:\Customer Database and CustomerData is at S:\Customer Database. Could someone help me with the code...
4
by: John T. Howard | last post by:
Can you issue commands from VB.Net to create and delete databases? I would like to create, delete, and copy MSAccess tables and/or databases from code. Can this be done? Can you show, or point...
2
by: angie | last post by:
I need to figure out how to create a user interface to search a query, but here's the bad part...I need to account for criteria on at least 7 of the fields. Here's what I'm thinking I need to do:...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
1
by: Dave | last post by:
I have multiple forms that will create an object. Basically a energy efficiency measure object. The measure object will have a couple of required properties set but after that it can have 10-20...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
0
by: ramuygl | last post by:
want to create store procedure that. want to send the table name as argument and retrive the data of that argument. and want to store data in temperary table using the insert query. HERE I AM...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
3
by: DeanL | last post by:
Hi guys, Does anyone know of a way to create multiple tables using information stored in one table? I have a table with 4 columns (TableName, ColumnName, DataType, DataSize) and wanted to know...
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
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,...
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
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...
1
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
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.