Solved

Create table column as CheckBox

Posted on 2012-04-12
10
371 Views
Last Modified: 2012-04-12
I have the below which does create the table, but I need to have the "Assign" column show up as a checkbox.  However, I don't seem to be able to get this done with what I have so far.

Public Sub CreateAssignTables()
On Error GoTo ErrorHandler
Dim tdf As DAO.TableDef
Dim pt As DAO.Property

'First create for exitance of tables and delete
If fntDoesObjectExist("tblTEMPAssignVar", "Table") Then DoCmd.DeleteObject acTable, "tblTEMPAssignVar"
If fntDoesObjectExist("tblTEMPAssignCon", "Table") Then DoCmd.DeleteObject acTable, "tblTEMPAssignCon"

'Create each table locally
Set tdf = CurrentDb.CreateTableDef("tblTEMPAssignVar")

With tdf
      ' The CreateField method will set a default Size if one is not specified
      .Fields.Append .CreateField("DeptName", dbText, 50)
      .Fields.Append .CreateField("UserID", dbText, 50)
      .Fields.Append .CreateField("TaskName", dbText, 50)
      .Fields.Append .CreateField("TaskID", dbText, 50)
      .Fields.Append .CreateField("Assign", dbBoolean)
End With

Set pt = tdf.Fields("Assign").CreateProperty("DisplayControl", dbBoolean, acCheckBox)
  tdf.Fields("Assign").Properties.Append pt
 
CurrentDb.TableDefs.Append tdf
CurrentDb.TableDefs.Refresh

Set tdf = Nothing

Exit_ErrorHandler:
    Exit Sub
ErrorHandler:
    MsgBox "Error Number; " & Err.Number & vbCrLf & _
           "Description: " & Err.Description & vbCrLf & _
           "Procedure: CreateAssignTables", vbOKOnly
    Resume Exit_ErrorHandler
End Sub
0
Comment
Question by:ssmith94015
[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
  • 7
  • 3
10 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37839582
change this

Set pt = tdf.Fields("Assign").CreateProperty("DisplayControl", dbBoolean, acCheckBox)

with

Set pt = tdf.Fields("Assign").CreateProperty("DisplayControl", dbInteger, acCheckBox)

or

Set pt = tdf.Fields("Assign").CreateProperty("DisplayControl", dbInteger, 106)
0
 

Author Comment

by:ssmith94015
ID: 37839927
I used Set pt = tdf.Fields("Assign").CreateProperty("DisplayControl", dbInteger, acCheckBox)

but it errors out on the next line where I append the property
tdf.Fields("Assign").Properties.Append pt
0
 

Author Comment

by:ssmith94015
ID: 37839931
Is there a library reference I should be setting?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:ssmith94015
ID: 37839937
The error I get is Error Number 3219 Invalid Operation

Sandra
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 37840114
use this  codes


'Create each table locally
Set tdf = CurrentDb.CreateTableDef("tblTEMPAssignVar")

With tdf
      ' The CreateField method will set a default Size if one is not specified
      .Fields.Append .CreateField("DeptName", dbText, 50)
      .Fields.Append .CreateField("UserID", dbText, 50)
      .Fields.Append .CreateField("TaskName", dbText, 50)
      .Fields.Append .CreateField("TaskID", dbText, 50)
      .Fields.Append .CreateField("Assign", dbBoolean)
End With

CurrentDb.TableDefs.Append tdf     'moved here

Set pt = tdf.Fields("Assign").CreateProperty("DisplayControl", dbinteger, acCheckBox)
  tdf.Fields("Assign").Properties.Append pt
 
               'CurrentDb.TableDefs.Append tdf ' move up
0
 

Author Comment

by:ssmith94015
ID: 37840155
Now it stops and the Set pt line.  I don't think this can be done in code no matter what I have found on line to say that it can.  I get an Object invalid or no longer set error.

I have the correct library references and all, but I am getting ready to simply give up.

Sandra
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37840166
don't panic..

try this codes


Public Sub CreateAssignTables()
On Error GoTo ErrorHandler
Dim tdf As DAO.TableDef, db as Dao.database
Dim pt As DAO.Property

'First create for exitance of tables and delete
If fntDoesObjectExist("tblTEMPAssignVar", "Table") Then DoCmd.DeleteObject acTable, "tblTEMPAssignVar"
If fntDoesObjectExist("tblTEMPAssignCon", "Table") Then DoCmd.DeleteObject acTable, "tblTEMPAssignCon"

'Create each table locally

set db=currentdb  
Set tdf =db.CreateTableDef("tblTEMPAssignVar")

With tdf
      ' The CreateField method will set a default Size if one is not specified
      .Fields.Append .CreateField("DeptName", dbText, 50)
      .Fields.Append .CreateField("UserID", dbText, 50)
      .Fields.Append .CreateField("TaskName", dbText, 50)
      .Fields.Append .CreateField("TaskID", dbText, 50)
      .Fields.Append .CreateField("Assign", dbBoolean)
End With

 
db.TableDefs.Append tdf

Set pt = tdf.Fields("Assign").CreateProperty("DisplayControl", dbBoolean, acCheckBox)
  tdf.Fields("Assign").Properties.Append pt

db.TableDefs.Refresh

Set tdf = Nothing
Set db= nothing
Exit_ErrorHandler:
    Exit Sub
ErrorHandler:
    MsgBox "Error Number; " & Err.Number & vbCrLf & _
           "Description: " & Err.Description & vbCrLf & _
           "Procedure: CreateAssignTables", vbOKOnly
    Resume Exit_ErrorHandler
End Sub
0
 

Author Closing Comment

by:ssmith94015
ID: 37840176
Got it to work with the below changes.  You gave me the idea for dbinteger and acCheckbox, but I realized thta it was using CreateTableDefs, not just TableDefs in the statement we well as moving it to the correct spot in the code<br /><br /><br />Set pt = CurrentDb.TableDefs("tblTE<wbr />MPAssignVa<wbr />r").Fields<wbr />("Assign")<wbr />.CreatePro<wbr />perty("Dis<wbr />playContro<wbr />l", dbInteger, acCheckBox)<br />        CurrentDb.TableDefs("tblTE<wbr />MPAssignVa<wbr />r").Fields<wbr />("Assign")<wbr />.Propertie<wbr />s.Append pt
0
 

Author Comment

by:ssmith94015
ID: 37840182
Yes, I was panicing!  Thank you for your help, this has been a thorn in my side for a good part of the date.

Sandra
0
 

Author Comment

by:ssmith94015
ID: 37840207
Below is the final full version of the code that works.

Public Sub CreateAssignTables()
On Error GoTo ErrorHandler
Dim tdf As DAO.TableDef
Dim pt As DAO.Property
Dim dbs As DAO.Database
Set dbs = CurrentDb

'First create for exitance of tables and delete
If fntDoesObjectExist("tblTEMPAssignVar", "Table") Then DoCmd.DeleteObject acTable, "tblTEMPAssignVar"
If fntDoesObjectExist("tblTEMPAssignCon", "Table") Then DoCmd.DeleteObject acTable, "tblTEMPAssignCon"

'Create each table locally - Variable tasks
Set tdf = dbs.CreateTableDef("tblTEMPAssignVar")
With tdf
      ' The CreateField method will set a default Size if one is not specified
      .Fields.Append .CreateField("DeptName", dbText, 50)
      .Fields.Append .CreateField("UserID", dbText, 50)
      .Fields.Append .CreateField("TaskName", dbText, 50)
      .Fields.Append .CreateField("TaskID", dbText, 50)
      .Fields.Append .CreateField("Assign", dbBoolean)
End With
    dbs.TableDefs.Append tdf     'moved here
    dbs.TableDefs.Refresh
Set pt = dbs.TableDefs("tblTEMPAssignVar").Fields("Assign").CreateProperty("DisplayControl", dbInteger, acCheckBox)
         dbs.TableDefs("tblTEMPAssignVar").Fields("Assign").Properties.Append pt
Set tdf = Nothing
   

'Create each table locally - Constant tasks
Set tdf = dbs.CreateTableDef("tblTEMPAssignCon")
With tdf
      ' The CreateField method will set a default Size if one is not specified
      .Fields.Append .CreateField("DeptName", dbText, 50)
      .Fields.Append .CreateField("UserID", dbText, 50)
      .Fields.Append .CreateField("TaskName", dbText, 50)
      .Fields.Append .CreateField("TaskID", dbText, 50)
      .Fields.Append .CreateField("Assign", dbBoolean)
End With
    dbs.TableDefs.Append tdf
    dbs.TableDefs.Refresh
Set pt = dbs.TableDefs("tblTEMPAssignCon").Fields("Assign").CreateProperty("DisplayControl", dbInteger, acCheckBox)
         dbs.TableDefs("tblTEMPAssignCon").Fields("Assign").Properties.Append pt
Set tdf = Nothing


Exit_ErrorHandler:
    Exit Sub
ErrorHandler:
    MsgBox "Error Number; " & Err.Number & vbCrLf & _
           "Description: " & Err.Description & vbCrLf & _
           "Procedure: CreateAssignTables", vbOKOnly
    Resume Exit_ErrorHandler
End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

730 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