How do I make large text boxes use null instead of blank string when empty - forms

Here is my issue. I am currently forced to use Access and I am writing some generic validation that I can add to forms.
It was all going well and catching empty fields in form_error based on the error "You tried to assign the Null value to a variable that is not a Varient data type"
All of my required varchar fields are NOT NULL.
Unfortunately if a textbox has a control source to a large varchar DB field it behaves differently. I can't remember the size threshold but assume this behaviour difference would be equivalent to text vs. memo in an access table).
Basically, if you delete the contents of a small text box control it attempts to write null and the error is caught. All good.
If you do the same on a text box linked to a larger varchar, or memo database field then it writes a blank string which is considered valid.
I have confirmed this by changing the db Schema between varchar(50) and varchar(256), updating the linked table in Access and restarting Access for good measure.
I am hoping someone can point me to a property to set or some tiny piece of generic code that can be added to make all text boxes behave the same regarding writing NULL/Empty string when they are empty regardless of the size of the DB field they are connected to.
Just to note that also the box behaves differently on insert or edit. If not filled on insert it does leave the DB entry as null.

That's pretty much the way you have to do it. You could set up a "Validation Rule" on each text field, but again that would require hunting down all the text controls.
You can make that job easier. If you check the Object Dependencies of the tables, you can get a list of all the forms (and queries, etc.) involved. Then you can be sure you have hit each one.

Related

MS-Access 2010 Form: field doesn't accept data source with 2 hyphens

I have a form based on a multiple-tables query. As some fields from different tables have the same names, I must add the corresponding table's name. However, there are hyphens in the tables' names as well as in the fields' names (both inherited from foreign Excel tables).
In VBA there is no problem: [Table-1.Field-1] always works well (also in SQL queries). However, when I write this in drafting mode as data source into the form, Access "thinks" this would be wrong and replaces it automatically with [[Table-1].[Field-1]] - with the result that the form then displays the error #Name?. I tried to replace [] by quotes but without any success.
Note that there is no error when only the table or only the field has a hyphen: both MyTable.[Field-1] and [Table-1].Myfield are accepted by the form.
The correct syntax should be:
[Table-1].[Field-1]
Or, using bang notation:
[Table-1]![Field-1]
Meanwhile I found not a true answer, but nevertheless a quite satisfactory workaround by adding following calculated field into the query:
MyWorkAround: [Table-1.Field-1]
Then I can simply refer to [MyWorkAround] in the corresponding form's field to avoid the form's bug. But this isn't really very elegant !
Note that I always use [ … ] around fields, even where not necessary. This practice helps avoiding a lot of errors.

"The data has been changed" error when editing underlying record in Access VBA

I have a form in Access where I have 2 unbound multi-select listboxes, with some code to move items between them.
Each of the fields in the table which are shown in the listboxes are boolean values - if the value is true then the name of that field shows up in lstSelected, and if false shows up in lstUnselected.
The listboxes have a RowSourceType of Value List, and the value list is generated programatically by looking at the underlying record and constructing a string with the field names where the boolean values are true for lstSelected and False for lstUnselected.
On the form I have two buttons, cmdMoveToSelected and cmdMoveToUnselected. When I click on cmdMoveToSelected it changes the boolean value of the underlying field for any selected items in the lstUnselected listbox from false to true by executing an SQL string, then rebuilds the value lists for both of the listboxes.
I have all of this working just fine. If I do a me.lstUnwanted.requery and a me.lstwanted.requery then everything moves and shows up correctly, and the underlying fields are edited correctly, BUT when I click on anything else on the form I get the error:
The data has been changed.
Another user edited this record and saved the changes before you attempted to save your changes.
Re-edit the record.
Now I've found a way around this (jobDetailsID is the primary key of the record being dealt with):
Dim intCurID as Integer
intCurID = Me.JobDetailsID
Me.Form.Requery
Me.Recordset.FindFirst "JobDetailsID = " & curID
This requeries the form and then moves back to the current record, and this gets rid of the error, however it causes there to be a delay and the form to flicker while it opens back at the first record, changes back to the correct record and repopulates the list boxes.
Is there a way to do away with this error, or get it to trigger programmatically so I can catch it by turning the warnings off via vba?
Thanks in advance.
Maybe it helps not to bind the form to the table being altered by cmdMoveToSelected, but to a query that doesn't contain all the boolean fields. If cmdMoveToSelected alters one or more boolean fields, the record is changed, but the query result isn't. Not sure if it's sound though.
It also sounds a bit like a design problem rather than a form problem, storing options in boolean fields instead of into a related table.
Probably the best solution would be to not directly update the current record in the table while the Form is dirty. Instead, update the values of the fields within the form itself (Me!FieldName) as the items are moved from one List Box to the other, and let the form write those values back to the table as usual.
I seem to have fixed it, though the fix doesn't make a great deal of sense to me.
I added in a Me.Refresh to the button click code, after I had requeried the two listboxes and it appears to have stopped the message from coming up. However this only works when I have the JobDetailsID textbox visible on the form (though I expect this is arbitrary and any field-linked textbox would work).
Can anybody explain to me why this works? I'd like to understand fully when to use requery, refresh etc
I've had this sort of thing happen when I've left the form RowSource query hanging in place after converting the controls to unbound textboxes, etc. The general Form rowsource query (to bring in all fields I might possibly end up using) provides me with a query-list identical to the table fieldnames, making it simple to select them for control-names as needed. Works fine, but you have to remove the form rowsource query after all the names are matched-up. (After which DLookup and BeforeUpdate works for getting and storing values and changes.)

FileMaker: Dropdown list with exact values in text

I have a drop down list of subjects. Two particular subjects are Mathematics and Additional Mathematics. When I choose Mathematics from the drop down list, records from Additional Mathematics and Mathematics are both displayed. Worse is that records from Additional Mathematics are shown first. Many colleagues made mistakes because of this.
How do I make the drop down list such that when clicked, the exact terms are used instead?
This is a problem that is not necessarily unique to FileMaker. You are searching for a name that is imprecise because it is a match for multiple names. Rather instead you might want to search for a unique key whose subject name is 'Mathematics' as displayed in your drop down. It is the use of that unique key that allows you to perform a precise search, even when the name of one subject is a partial or complete match for another.
This solution requires you to add a unique serial number which is, in your case, to alter the Subjects table and add a field called 'idnumber' or similar. The field type should be Number, and the options should include Auto-Enter-Serial number-Generate and On creation-increment by 1. The trick here lies in making sure no two subjects have the same 'idnumber' even when you aren't paying attention, so set the next value to something greater than the number of subjects that already exist. Then from another layout assign each existing subject a unique idnumber, noting that if there are a great many subjects you could script that step.
I should mention that many recommend a best practice of never changing a production layout, but rather to duplicate the layout and make the required changes to the duplicate. This minimizes the effects of testing your changes etc.
Finally, change your layout in inspector such that the drop down list shows Use values from field: 'idnumber'. Select Also display values from second field: 'Subject' and Show values only from second field. Now your drop down is the same clean selection as before. The field will not look correct yet because it will show a number. To make it look correct you can insert another field, selecting 'Subject'. Place that field over top of the 'idnumber' and send 'idnumber' to the back. Fill the 'Subject' field with the correct background solid color instead of none, and enjoy your new precision search capability! The entire process is handled server side so it should not matter that client access is IWP.
If you're using the selection to do a find, put an "==" before the text you're searching on. This will tell FileMaker to do an exact field contents search, instead of a "contains" search.

Filemaker - How to add new instance of related record from parent record layout

I am new to filemaker pro so hopefully this isn't too stupid of a question. I took a few online classes and everything makes sense except for when I want to work with related fields. I tried to find this one google but I am either searching with the wrong key words or it just ins't really out there.
Basically I want to create a new record and be able to add references to its related fields. I have messages which can have numerous speakers. These speakers are references to the message table via a message speaker xref table. I am able to display the speakers that are already in the database (I imported the data from another source that already had many values) but I am not able to add new ones from the message layout.
I would like to just use the popup control with a multi selection. The problem I am running into is when I add a new message the popup control doesn't populate with the records from speakers.
I already tried this by adding a button to execute sql to add the reference with a default speaker but I wasn't able to get the script to execute correctly. I am not even sure if that is the best way.
Hopefully this makes sense. My rep is still to low to post images otherwise I will attach the DB connections.
This is an older post, however I wonder if your problem is solved. In FileMaker's layout mode inspector you can specify a "Values from:" parameter. When you select the field, change it's Values from: and create a new value list. Set that new value list to "Use values from first field" for speaker names. If the speaker table has a primary key field then you can instead set a foreign key value for the speaker. To get fancy you can select and display the FK field using a drop down arrow, then overlay a text field over top of the FK field to present the speaker's friendly name.
HTH.

Access comboxbox selection needs to change value in label control

On a form, I have a combobox, with the RowSource coming from a query (specifically, a calculated field in the query). When the user makes a selection, I want to update a label on the same form with a different column from that same query, but of course associated to the selection.
I'm fine with VBA and writing queries and whatnot, but I am not very familiar with Access forms.
By the way, I tried searching for an answer to this, but it was quite difficult because I don't know what this thing is really called that I am trying to do. A good link to a site explaining this would be perfectly fine (no need to write a bunch of stuff here if it already exists elsewhere).
In the After Update event of my combo box, cboUserID, I can set a label control, lblFoo, to the value of the second column in the selected row of the combo.
Me.lblFoo.Caption = Me.cboUserID.Column(1)
If your combo box is bound to a field in the form's record source, you may want to do that same operation from the form's On Current event also.
You can use the column property to refer to anything other than the bound column of a combo.
Rowsource: SELECT ID, SName, FName FROM Table
Me.MyCombo.Column(2)
This would return FName.
-- http://msdn.microsoft.com/en-us/library/aa224084(v=office.11).aspx
Me.MyLabel.Caption = Me.MyCombo.Column(2)