How to set a look up field value to null/blank in access 2010? - forms

I need some help with Access 2010 forms. My form has a number of fields (from one table). One of the field is a logical field. If the user selects true, then the next field (text field) should be enabled. This is working fine - I created an after update event procedure. The problem I have is if the user accidentally selects true, and then selects a value/s for the text field (the text field looks up a query - it is a look up field and it can have more than one value - the user can select/check as many from the list and they will be stored to the text field, separated by coma).
How will I set the text field (look up field) value to blank, if the user goes back and set the logical field to false? me.textfield.value = null gives an error.
Can anyone please help me? Thank you!

Just keep in mind that in fact a multi-value column is in fact a normalized data table.
So the display looks like this:
To clear the records selected in this child table, which is your mult-value selection, you can use this code behind the above button:
Dim rstChild As DAO.Recordset
Set rstChild = Me.Recordset.Color.value
Do While rstChild.EOF = False
rstChild.Delete
rstChild.MoveNext
Loop
Me.Color.Requery

An easy way to insert a blank lookup field is to select the field in design view and click on the lookup tab in the field properties. Before the first entry in Row Source insert the following " ";

Related

How to store DLookup from [Form] to Table Field in MsAccess 2013?

I have two MS Access tables: IdMhs and T_UKT. I want to automatically fill in [IdMhs].[SPP] from some criteria in [T_UKT].[UKT]. I cannot put it in query relationship, because the row cannot be edited on a form.
So I make a form and I get the number SPP (a textbox on form) automatically by using and it works fine:
=DLookUp("SPP";"T_UKT";"UKT = " & [Form].[UKT])
The problem is: the lookup value just shows on the form, and the results are not filled in the field in table ([IdMhs].[SPP]).
Any idea what an expression I should write to fill it in IdMhs table automatically?
Need macro or VBA code to save value into table. If form is bound to IdMhs table, simply like:
Me!SPP = Me.tbxSPP
The real trick is figuring out what event to put the code into. You have a control (possibly combobox) where the UKT value is selected? Use its AfterUpdate event.
Why do you need to save the SPP value and not just retrieve it in a query that joins tables?
What is nature of table relationship? Is T_UKT a lookup table? If so should be able to include it in form RecordSource and then the SPP value would be available for display in textbox and DLookup not needed. Domain aggregate functions can perform slowly on forms and reports and should be a last resort option. The same code would be used to save the value. The query join should be 'show all records from IdMhs and only those from T_UKT that match'. Set textbox bound to T_UKT SPP field as Locked Yes, TabStop No.

How to retain the value of an editable text field in a Lotus Notes form every time the user opens it?

I have a form in Lotus Notes containing an editable text field.
Once the user enters a value in that field, it gets saved properly when I check it by opening the document from the back-end.
But I need this value to be seen in the form every time the user opens the form.
Because it is a configuration form where the user should be able to see all the values saved.
For example, a field which contains the path to download a report. And it should be an editable field itself. Is there any way to do this? Any sort of clue or help would be really appreciated. Thanks in advance!
The value of an editable field stored in a document does keep it's value every time the user opens the document.
It sounds like you may ask for something else. You want User A to create a document, enter a value (i.g. a download path) and save the document. When User A or User B later creates another document based on the same form, the previously entered value should be the default. Is that what you mean?
In that case you could simply use #DbLookup or #DbColumn in the formula language in the Default Value property of the field.
Or create a lookup view with the previously created document, sorted descending by date, then use the GetFirstDocument method of the NotesView class to get the first document in that view and read the value out of it using the GetItemValues method of the NotesDocument class.
Performance tip: If you make sure the value you want to look up is visible in the lookup view you can use the GetFirstEntry method of the NotesView class, then use the ColumnValues property to get the value, this is much faster.
Solution is to use #DbColumn in the default value of the editable text field of my form

web2py SQLFORM.factory defaults not updating

I have an SQLFORM.factory on a page that I use to(among other things) update a particular field in a table. That field is a drop down table I made like so
Field('visibility',requires=IS_IN_SET(['everyone','subscribers','friends','nobody']))
So the field in the SQLFORM.factory looks the same. The difference is that I want the default in the SQLFORM.factory to be the current value of that field in a particular table. by making a default. I do a query on the desired entry on the table, select that field, and that becomes my default, the selected option. Perfect the first time you load it up.
I do the update after the form accepts like so and the update works functionally:
if subForm.accepts(request,session,dbio=True):
if myForm.vars.visible != theDefault:
db(row).update(visibility = subForm.vars.visibility)
If you submit the page the selected option is not the current value of that field in the table, it's always the one it was previous. If I look at my database admin the table updated fine but I could not fetch the right option to select as my default. If my default was 'everyone' and then I select and submit 'friends' then the selected when the page reload after the submit is still 'everyone' If I then select and submit 'nobody', after the refresh it is 'friends'.
If it helps, I am displaying the view this SQLFORM.factory is in in and iFrame as part of a bigger page.
After many hours, here's how you do it(sorta hackey but it works)
#This is a kludge to get the right default visibility selected
if request.vars.visible == None:
visibleDefault = theDefault
else:
visibleDefault = request.vars.visible
form = SQLFORM.factory(
FIELD(Field('visible',requires=IS_IN_SET(['everyone','subscribers','friends','nobody'],zero=None),default=visibleDefault),
table_name='table')
if form.accepts(request,session,dbio=True):
if form.vars.visible != theDefault:
db(row).update(visibility = form.vars.visible)

Invisible value when creating new record

I have problem with some form in Access 2010. In one of the fields (Amount) I have as a value expression =IIf([IsNull([Code]);1;2) . In the form the values 1 and 2 are shown correctly but when I try to save the newly created record I have an error: You have to fill the Amount field. Can someone tell me why the value is not visible when saving new record to database?
You need to use VBA code on the NewRecord and/or BeforeUpdate event to insert these values into this field/textbox. What you are doing here amounts to setting a value for Display only.

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)