Solved

Append field to database during run-time

Posted on 2001-06-20
5
173 Views
Last Modified: 2010-05-02
I am very new to VB and I am trying to append a new field to a database with the name of the field being a string the user enters in (boolean-type field) and I am getting stuck.  I am trying not to use SQL statements or adodb connections because I don't really understand them. I tried:

 MattressType.Recordset.Fields.Append txtHardness.Text

but it gives me a run-time error of "type mismatch" and highlights the "txtHardness.Text" which is a string but I think I'm supposed to have an object there. Please help me as I am very confused (as you can probably tell).
Thanks!
~Sarah
0
Comment
Question by:snaegs99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Expert Comment

by:rkot2000
ID: 6211389
Append does not append a field to the database, it allows to build a dynamic recordset.
If you want to change/alter a table you need to use tsql ? for sqlserver or sqlplus for oracle.
0
 
LVL 3

Accepted Solution

by:
jrspano earned 50 total points
ID: 6211455
for sql server 7 and 2000

alter table tablename ADD columnname FLOAT NOT NULL

this adds a column named columnname that has float for type and doesn't accept nulls.
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6211458
you really should learn to understand ado.  there is only so much you can do without them.
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6211766
If you want to append a field you must use the TableDef object and append a field object, using ADO and SQL would be much easier and more worth your while to learn for many other reasons.

But here is a sample I used to use with VB3, DAO and Access 2.0

    Dim db as Database
    Dim tb As New TableDef
    ReDim fd(0 To 6) As New Field

    Set db = CreateDatabase(DBName$, DB_LANG_GENERAL)
    tb.Name = "language"

    fd(0).Name = "text"
    fd(0).Type = db_text
    fd(0).Size = 255

    tb.fields.append fd(0)

    db.tabledefs.append tb

hope this helps
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139597
Hi snaegs99@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept jrspano's comment(s) as an answer.

snaegs99@devx, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBS file using code from 2nd file (txt or vbs) 4 56
Assign a value in Excel V-Basic 3 38
VBA Replace Function - What am I missing? 3 51
2 Global Vars, 1 List Box 4 33
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question