display control doesn't have checkbox - ms-access

I have a lot of checkboxes (with yes/no fields in the underlying tables) and lately Access has been crashing a lot. After some research it seems null values in the checkboxes could be to blame, so I set out to follow Allen Browne's instructions (http://allenbrowne.com/NoYesNo.html) for replacing them with number fields. Everything was going great until I got to the step where I set the display control to 106 (checkbox). This is not an option in the table and I don't understand why. I set my table up like he stated but I only have the option for a textbox, listbox, or combobox.
I also tried just typing 106 into the Display Control field, but it gives me an error that it isn't an item on the list. In his article, he mentions to fix the error above to use SetPropertyDAO(), but I have no idea what that means, how to do it, or where to do it. Do I built it in code somewhere? The link he has brings you to a script where he uses that to fix his printers or something.

Close your table.
Open Immediate Window with Ctrl+G
Paste the code:
CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl") = CInt(acCheckBox)
Replace table and field name to your names.
Run the code by putting the cursor at the end of the line and hit Return.
If you get an error, open the table in design view, and set the display control to something (it doesn't matter what), save and close, repeat.

Related

Access Report Query pulling from Form instead of table

I have a report that changes based on the query used in the record source.
I did this to consolidate 6 different reports that printed the same formate and to the same label printer but they all used different data types/sources. I was able to convert all by 1.
The one I am having trouble with is one where there is a form, with a combobox and a textbox. The combobox has a table that its connected to with 11 different symbols ranging from Hearts to & and # stuff like that. The textbox will take any number/text combo.
When I run a query that I set up with [Forms]![frmPrintPtouchLabel]![txtName] and [Forms]![frmPrintPtouchLabel]![cmbSymbol].
The query pulls the right information except for the symbol that columb is left blank. Can anyone provide any reasoning as to why this is happening and how I can fix it?
Thank you.
Looks like there was fluke somewhere in my code or I was just over thinking something. After setting up a blank query I set a field: Symbol: [Forms]![frmPrintPtouchLabel]![cmbSymbol], and a field Name: [Forms]![frmPrintPtouchLabel]![txtName]
and I set up a button in a form that does DoCmd.OpenQuery "qry_TestQuery", in that same form there is the combobox with the Symbols, and a textbox for the Name, when I input those two and click the button the query opens with the proper information. Thanks for all that helped.

Unfreezing columns in a subform in Access

I have a form with a subform that displays records, and the user is able to rearrange that subform and save their preferences. This means they can change the width of the columns, the order, hide columns, etc. and save their changes at any time, and those changes are applied when the form next loads. This is done by saving the preferences in a table and then pulling those preferences from the table in the subform's Form_Load event. This all works fine, but I'm trying to add the ability to save frozen columns as well. I'm able to track how many columns are frozen, and I'm also able to restore the order of the columns, so it should be a simple matter to unfreeze all of the columns and then refreeze the first X columns.
I know that I can use 'RunCommand acCmdUnfreezeAllColumns' to unfreeze all of the columns. I also know that I need the focus to be on the form, so I tried to do myForm.setFocus (where myForm is a reference to the subform) before unfreezing the columns. This gives the error "There is an invalid method in an expression". I thought maybe this was because you can't set focus to a form with enabled controls, so I tried myForm.Controls(0).SetFocus instead. This doesn't give an error, and it seems to set the focus to the first cell in the subform based on the value of Screen.ActiveControl (and the fact that the cell has the focus after the form loads). However, I then get the error "The command or action 'UnfreezeAllColumns' isn't available now." on the line RunCommand acCmdUnfreezeAllColumns. I also thought maybe I was having problems because I was trying to focus in a load event, so I tried calling the repaint method first, but that didn't make any difference. I thought about unfreezing all of the columns in the design view so that I wouldn't need to unfreeze them at runtime, but the user may not have any preferences saved and I want some columns frozen by default.
I'm running out of ideas on this. What exactly needs to happen for the command to unfreeze all columns to work? Or is there an easier way to do this that I'm missing? The solution needs to be versatile enough to work on any subform with any field names. Note that I do have a list of the field names that were present when the user saved their preferences, but I cannot guarantee that they will still all exist when their preferences are restored.
This normally worked for me:
myForm.SetFocus
RunCommand acCmdUnfreezeAllColumns
However, sometimes it failed, so I tried to repeat it:
On Error Resume Next
myForm.SetFocus
RunCommand acCmdUnfreezeAllColumns
If Err.Number <> 0 Then
myForm.SetFocus
RunCommand acCmdUnfreezeAllColumns
End If
On Error GoTo 0
That nearly always worked, but the menu commands are not 100% reliable.

Access 2013 Recordsource quirk

I'm doing some development work on an Access 2013 database. Originally, it was designed so that the record source was set at design time and a filter was added to restrict the records on Open. For a couple of reasons, I changed this to where the record source is being cast in code as the form opens -
Me.Form.RecordSource = SQLstr
But when I do this, where the form should be displaying 5 records, it only displays 1 and that is a new record.
When I look at the query in the design screen, the query returns the correct record set.
Curiously, when the form is open, at the bottom of the form, the filter button is yellow. When I click on that, the whole set shows. When I click it again, the set does not change, but continues to show the same (correct) set.
I don't see any code in the filter (there was, but I've removed it). If I clear the Filter in code, then the filter button is disabled and I can only see the one record.
Does anyone see something I'm missing here?
Thanks -
Alan
OK, it looks like I was going too far in referencing the form:
Me.form.RecordSource = SQLstr
puts the code in the correct place (or seems to) but doesn't execute right.
If I use:
Me.RecordSource = SQLstr
Then it works correctly - displays no filter icon on the form and show the right result set
Not sure how referencing the form causes a problem and why (if it causes a problem) it doesn't fail. But that's what I'm getting

Control can't be edited; it's bound to an unknown field [FieldName]

I have 2 bugs beginning to show up in my app, both in subforms. New text boxes, labels and check boxes will only display in design view.
Bigger problem: I can add a check box by dragging it from the field list but get the error 'Control can't be edited; it's bound to an unknown field [FieldName]' when I attempt to click it in form view.
I can edit the value directly in the table and I can edit the value in the form's underlying query as well.
I've tried decompiling/recompiling and importing all my objects into a new database. I tried using a different machine to see if there was something wrong on mine. nada
This is an existing application with hundreds of man hours into it. I can't just start from scratch.
I was getting this - It took me a while to realize because the error statement only persisted while data list item was click-depressed. It turns out in my case that somehow a number of spaces existed in the Control Source property. I found this when I entered the table name in the field and the error statement switched from Control can't be edited; it's bound to an unknown field '(bunch of spaces) ' to Control can't be edited; it's bound to an unknown field [tableName]. After deleting the [tablename] and ensuring no spaces in Control Source, the combobox toggled to 'unbound' and there was peace in the valley.
I had a similar problem. After many hours of work I discovered that all of a sudden I had to add the table name to the Control Source property.
Go to the properties for the control and add the table name i.e. tbl_MyTable.MyField.
I have no idea why Access sees an ambiguity problem all of a sudden for just that one field but that was obviously the case.
I had this problem and tried adding the table name to no avail. On the load event of the form, I changed the recordset (same table but filtered using what is passed by me.openargs instead of on the docmd.openform command due to needing the id passed for other things to work) in VBA. I thought that once you set the form to the recordset, you were done and could close the recordset. Not so, leave the recordset open until you actually leave the form or this error will occur.
Change the control source from "=[Some_Value_in_Table]" to [Some_Value_in_Table]. To be more precise remove the equal to sign.
I tried all these things - to no avail. I had a few fields bound and only one of them was causing grief - the others were fine. I swapped the Control Source around between controls to isolate the issue - it was definitely only related to the field somehow - after refreshing external links, removing and re-adding the offending field from the Access query opening and closing the offending form - everything somehow fell into place - I can't say exactly what fixed the problem - but my life can now return to normal! In a nutshell - these are the steps I followed:
* refresh links to external table
* remove and re-add fields in query
* confirm the the field is editable at the query level
* copy and paste the table.fieldName from the query's sql statement
* save - close query
* paste into the Control Source
* save and close form!
Good luck!

SUM() on a form footer resulting in #Error

I'm trying to display the sum of a field in a text box in the form footer. The field is not calculated in any way.
Here are a couple of the things I've tried:
=Sum([txtWeldInches])
=Sum([WeldInches])
=Sum(CDbl([txtWeldInches]))
=Sum(CDbl([WeldInches]))
...well you get the idea. Each iteration I've used results in the Text Box displaying #Error Without exception.
I've used similar constructs in different forms in the same project, so I'm not sure what the problem might be.
Has anyone run into this before?
EDIT:
I ended up writing a VBA routine to update the boxes when it was likely that they would be changed rather than trying to get a bound sum() function to work.
http://support.microsoft.com/kb/199355
All of the domain functions are based on the same query (over the underlying recordset). If one of the bound functions on the form has a binding error, all of the functions on the form will return an error.
In other words, make sure all your footer controls are resolving properly and not hitting any nulls.
If you use a SUM or AVG then make sure you are also using the Nz function:
ControlSource = =SUM(NZ([FIELD],0))
Is the field "WeldInches" existing in the data source for this form?
What datatype the field "WeldInches" is?
EDIT: I have looked at all your comments. If it doesn't work by databinding, try and use the unbounded way. At runtime, get the value of WeldInches using DSUM and set the footer textbox's value when the form loads.
Also, remember to update it at places where you think the SUM could change.
I had the same problem as Rister.
The source of the form was an underlying query.
I had a bound text box named txtQty on this form. Its control source was Qty (based on the underlying query of the form).
I created an unbound text box and entered =SUM([txtQty]) and received an error.
I tried various ways to find a solution and was very desperate.
Then I deleted the underlying query and created a new one using the same name and fields as before.
Then I entered =SUM([Qty]) into the unbound text box on the form and voila, it worked. Note that I didn't enter the name of the bound text box (txtQty) into the expression, but its control source (Qty). I don't know why, but it worked for me.
I know you said "Form" but for those who have issues with the Sum formula in an Access "Report" the formula has to be in the Report Footer NOT the Page footer. Took me a while to figure it out as Access defaults to only showing the page footer.
You want to sum by the name of the column in the record source: SUM([WeldInches])
Make sure there are no other textboxes with the name WeldInches.