Can i add fields to a table in access using visual basic 6 ?

G

Guest

hello....

i have 2 tables, 1 is people and the 2nd is assignments. i need to add to
third table for each day in the month variable number of assignments for
instance, 2 cleaning assignments at 1st of the month and 3 in the 4th of the
month so the table should hold the date and a field which will get the name
of the assignment and will hold the number of how many times to do it in that
day. the problem is that i have different amount of assignments to do each
day... is there a way to add field to the table from visual basic 6?

thank you for the response , i'm really lost with this problem
have a great week...
tzach
 
T

Tim Ferguson

=?Utf-8?B?VHphY2ggU29sb21vbg==?= <Tzach
(e-mail address removed)> wrote in

so the table should hold the date and a
field which will get the name of the assignment and will hold the
number of how many times to do it in that day.


I _think_ you want to add a new record rather than a new field: if I have
misunderstood, please post more details of your tables and keys.

Adding a new record is easy: VB6 is in lots of ways similar to VBA.

dim jetSQL as String

' this assumes you have a .mdb database and you are
' using DAO to connect to it. ADO and/ or SQL server
' require slightly different syntax
jetSQL = "INERT INTO Assignments " & vbNewLine & _
"(AssigDate, AssigName, NumOfTasks) " & vbNewLine & _
"VALUES (" & vbNewLine & _
Format(someDate," \#yyyy\-mm\-dd\#") & ", " & vbNewLine & _
" """ & someName & """, " & vbNewLine & _
Format(someNumber, " 0") & ");"

' check out that it looks right
debug.assert vbYes=MsgBox(jetSQL, vbYesNo, "Is this okay?")

' create a dbengine having declared it in your references
dim dbe as New DAO.DBEngine
' and get the database
dim db as DAO.Database
set db = dbe.OpenDatabase(somePathToMDB, false, false)

' then run the command
db.Execute jetSQL, dbFailOnError

' and close everything down
db.Close

You will need to supply values for the someName, someDate and someNumber,
presumably from some kind of user form etc.

Hope that helps


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top