Attachments do not display (Blank frame) with "IIf" statement - sql

I need to make a conditional display depending on a boolean value. (If true => display attachment, else display default img/nothing.)
The two tables :
T1(long T1_ID, txt firstname, attachment visa)
T2(long T2_ID, long fk_T1_ID, bool isValid)
So I used IIf statement :
SELECT T1.firstname, IIf(T2.isValid,T1.visa.FileData,Null) AS validSignature
FROM T1 INNER JOIN T2 ON...
Then I put validSignature as my source control into an attachment controller but it never displays anything...
When I display .FileName instead of .FileData into a textfield it works properly : it displays the right filename only when isValid = TRUE. But I NEED to display the picture itself, not only filename.
I have no idea of what I did wrong, so I am asking for your help.
Thank you

Rather than bogging your database down with attachments, why not store the pictures in a folder and make the t1.visa field store the filename.
Then just set the imagecontrol.picture = t1.visa
I did this with an inventory database. The user clicks a button to open a filepicker to select photos to associate with each inventory item, and move them to a folder. I used a separate images table and put and image control on my form with buttons that will allow them to flip through available photos for each item as well as change which photo is loaded as default. I can share the code if that is along the lines of what you want to do.

Sorry about the syntax...i'm on my phone, but like I said I would use an event procedure rather than iif statement in the control source.
Private sub your form_current()
If me.isvalid = true then
Me.imagecontrol.picture = me.visa
Else
Me.imagecontrol.picture = "default image path"
End if
End sub

Related

SAP B1 Choose from list employee but show name instead of code

We had a choose from list on the service call for default technician which appears to have shifted since turning on multiple scheduling and upgrading to SAP B1 V10.
I need to get this technician field back onto the main form (via udf) where it can be used to show the default technician from the BP master data.
My issue is if i have a choose from list from the employee master data it is returning the code into the edittext field whereas i need the employee name but still have the choose from list and golden arrow to work.
Appreciate the assistance on this.
add a hidden edit Text to contain the code (or use a property / variable / or get from the dBDatasource )
if using a hidden box:
Trap the Choose from List Event and use the SelectedObjects to
place the name into visible edit text & code into the hidden one.
Private Sub myNameBox_ChooseFromListAfter(sboObject As Object, pVal As SAPbouiCOM.SBOItemEventArg) Handles myNameBox.ChooseFromListAfter
myCodeBox.Value = pVal.SelectedObjects.GetValue("UserCode", 0)
End Sub
otherwise just set the edit text cfl binding to Display the Name:
myNameBox.ChooseFromListAlias = "UserName"
to get the link button working simply Trap the Link button press before, set to bubble event false & manually open the desired form using the key from the hidden edit text / dbDatasource / Property
BubbleEvent = False
Application.SBO_Application.OpenForm(SAPbouiCOM.BoFormObjectEnum. formType , "", myCodeBox.Value)

How to allow a combobox to be left blank//skipped on a form

I am relatively new to Access and any SQL and VBA I have picked up is self-taught, so I would really appreciate answers that are not too heavily laden with technical terms...that said, I am having an issue with allowing comboboxes to be left blank on a form if the user chooses not to input data. Also, I am using Access 2016.
Initially the problem I ran into was that if a combobox was entirely skipped and left blank, or if the user selects the combobox and then tries to move on without making a selection from the list, they got the error "You tried to assign the Null value to a variable that is not a Variant data type," and were unable to move on to any other fields on the form or to save the record being entered.
I found this article that details a possible solution, but I can't seem to get it to work. I made an unbound combobox, set the Row Source to:
SELECT EmailID, PersonalEmail FROM EmailT UNION SELECT "<N/A>","<N/A>" FROM EmailT
ORDER BY PersonalEmail;
where PersonalEmail is a field of type short text and the EmailID is an autonumber. I also followed the article's steps for formatting the combobox (column width, etc.) and set it to Limit to List = Yes.
Here is my exact code:
Private Sub Combo62_AfterUpdate()
If Combo62 = "<N/A>" Then
EmailID = Null
Else
EmailID = Combo62
End If
End Sub
Private Sub Form_Current()
If IsNull(EmailID) Then
Combo62 = "<N/A>"
Else
Combo62 = EmailID
End If
End Sub
< N/A> now shows up on my list, but if it is selected I get the error: "The value you entered isn't valid for this field. For example, you may have entered text in a numeric field or a number that is larger than the FieldSize setting permits."
Access's debugger highlights the line:
EmailID = Null
but I am not sure what steps I should take now to try and fix this.
I am completely open to other methods of allowing the combobox to be left blank if someone knows of a better way to do this also. For all I know, I am missing something really obvious! Thanks in advance for any insight!
EDIT: Thanks for your help guys, I never did figure out what exactly the problem was, but I got some advice from another forum to rethink my database design so this ended up being a null issue--it's all totally different now!
If the recordsource for your form contains a query with one-to-many relationships this error may come up. Try to use only the base table as the recordsource for the form. Use subforms if you need to display related data. The rest of the code may then be unnecessary.

Access 97 hide or show an Image by checkin a value of the query

I'm working with an old access 97 project, i can't update it. I have a continuos form that give me some results.Each row contain many values and i have one image to the right that must be hide/show by checking on of the other value returned by the query. The value that must be checked each row is named "Status" and the image that must hide/show is named Img1, so i have tried something like this:
Private_Sub Status_Enter()
Valore=Status.Text
if Valore = "O" Then
Img1.Visible=true
else
Img2.Visible=false
end if
end Sub
I have used Enter event cause i can't find an event that is called each time the status is created (but maybe i'm thinking too much as a php developer...), anyway this method isn't called. How i can do to achive this result: An image that hide/show each row by check the value of "each row Status".
The event you are looking for is Current event of the form.
However, setting the Visible property of Img1 control in the Current event is not going to help you as it will show/hide the control for all the records.
From Access 2000and onward you would be able to use conditional formatting to enable/disable the image, but not to show/hide it. Anyway, in Access 97 this feature is not available.
You may need something like this:
Private_Sub Status_Enter()
Dim Valore As Boolean
Valore = (Me!Status.Value = "0")
Me!Img1.Visible = Valore
Me!Img2.Visible = Not Valore
End Sub

navigation subform requery stopped working

I've built an unbound form which allows a user to select from two combo boxes that contain related information (Zone and Watershed Unit -- each Zone contains multiple watershed units) in order to see what regulations apply to each. Based on these selections (stored in txtZone and txtWU on the main form) a subform would show the existing regulations (sfrmRegsbyZWU based on qryRegsbyZWU). This serves as a reference for the user, who picks a new regulation to add from another subform, clicks a button, and the selection is added to the regulations for the Zone/Watershed Unit selected. I had this successfully built with a workaround in the OnCurrent event of the subform (which was undesirable because the user couldn't click on a record and delete it) and everything worked until I added inserted code to change the query definitions for the query which is the basis for the subform as opposed to having it in the "On current" event of the subform.
At that point the requery syntax in the main form which had previously worked stopped working. This is in all embedded in a navigation form in Access 2010, so the previously working syntax was:
Forms!frmNav!NavigationSubform.Form.sfrmRegsbyZWU.Requery
I've tried every permutation of Requery I can think of, and I can not get it working. The underlying query has been changed, but the form doesn't update to reflect it. Can anyone explain to me what has gone wrong, and how to fix it? The code (attached to the _After Update() event of the combo boxes) is:
Private Sub cboZone_AfterUpdate()
'Changes WU combo box as well as the underlying text boxes
Me.cboWU.SetFocus
Me.cboWU = ""
'Blank out other selections
Me.txtWU.SetFocus
Me.txtWU = ""
'Update text box with combobox selection
Me.txtZone.SetFocus
Me.txtZone = Me!cboZone.Column(0)
'Change the query underlying the Existing Regs panel (frmRegsbyZWU, qryRegsbyZWU) to reflect selection
Dim strZSQL As String
Set qdfZ = CurrentDb().QueryDefs("qryRegsbyZWU")
Dim myZVar As Variant
myZVar = Forms!frmNav!NavigationSubform.Form.txtZone
'MsgBox (myZVar)
If IsNull(myZVar) Then
strZSQL = "SELECT * FROM tblRegulations WHERE FALSE"
Else
strZSQL = "SELECT * FROM tblRegulations WHERE Zone_No=" & Forms!frmNav!NavigationSubform.Form.txtZone
End If
'MsgBox (strZSQL)
qdfZ.SQL = strZSQL
'DoCmd.OpenQuery ("qryRegsbyZWU")
Forms!frmNav!NavigationSubform.Form.sfrmRegsbyZWU.Requery
Thanks in advance for any help!

Validating Attachment in Richtext field

I am using below code to validate the Attachment in Richtext field.
If I will not used Call source.Refresh(True)
then validation is not working, but this code is also refreshing document everytime querysave is called in buttons.
So is there any option or any other idea so that I should not user this Refresh part or entire code to validate .
If anybody have more efficient code then please share this.
If Source.Document.YesNo20(0)="Yes" Then
Call source.Refresh(True)
Dim rtitem As NotesRichTextItem
Set rtitem = source.Document.GetFirstItem( "Atchmnt20" )
NotesEmbeddedObjectArray = rtitem.EmbeddedObjects
If Isempty ( NotesEmbeddedObjectArray ) Then
Messagebox "Please enter an attachment in 20a. As you selected option Yes"
continue=False
Exit Sub
End If
End If
There's a way in LotusScript to check attachments presence even for new (not saved) documents.
Create a hidden computed field, for instance AttachmentNames with formula:
#If(#AttachmentNames!=""; "1"; "");
In LotusScript do the following:
'in new documents Form field may be empty
If doc.Form(0) = "" then
doc.Form = "YourFormAlias"
End If
'computing doc contents with the form
call doc.ComputeWithForm(false, false)
If doc.AttachmentNames(0) = "" then
MsgBox "Please attach a file",,"Attention"
Continue = False 'if you are running this code in QuerySave
Exit Sub
End If
Validating rich text fields in Lotus Notes is a bit of a dark art, but can you not just do this? (where doc is the back-end):
If(doc.HasEmbedded) Then Continue = True
There are other things you can do. Check this Lotus Developer Domain post, which covers attachments, text, embedded objects, all sorts:
http://www-10.lotus.com/ldd/nd6forum.nsf/0/8b3df10667d355768525719a00549058
Can you validate RT field with formula?
I created a hidden field below my rich text field with this Input Validation formula:
REM {Validate just when saving};
#If(!#IsDocBeingSaved; #Return(#Success); "");
REM {Should contain some file};
_filenames := #AttachmentNames;
#If(
#Elements(_filenames)=0;
#Return(#Failure("You should attach at least one file"));
#Success);
Assuming that you want to avoid the Refresh because it takes too long, here is what you may want to look at and if feasible, try to change:
Maybe you can use the "Entering" event of the RichText field in conjunction with a global variable (in the form) to skip the Refresh in your code, if the RichText field wasn't touched at all.
Are there keyword fields with "Refresh choices on document refresh" option enabled that may be safe to disable? Or even place a button that would bring up a dialog and populate the field with the selected keyword(s) - refreshing the choices won't be neccessary then, as you can always present up-to-date choices through #DbColumn/#DbLookup or NotesUIWorkspace.PickListStrings.
Is there any code (LotusScript or Formula) in "Queryrecalc" and/or "Postrecalc" form events that may be possible to optimize? For example by using a global variable (in the form) as a flag whether to execute the code in Queryrecalc/Postrecalc - set it to false just before calling Refresh in your code, then set it back to true (because this Refresh only serves to update the RichText field to the backend document).