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
Solved

Create table column as CheckBox

Posted on 2012-04-12
10
368 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
  • 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

829 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