I used the below document to fix existing contacts' FileAs entries. It didn't work for contacts that were company names.
https://learn.microsoft.com/en-us/office/vba/outlook/concepts/address-book/programmatically-change-the-display-format-for-all-contacts
Because the Firstname and Lastname fields were blank, it made the FileAs entry blank(" "+" "+" ").
How do I look for the blank FileAs field and set the CompanyName field as the FileAs field?
It would be something like this:
Set contactItems = items.Restrict("[MessageClass]='IPM.Contact'")
For Each itemContact In contactItems
'The underscore on the line below breaks the line into two lines.
'You need the left side of the equals for each condition in the if cant do or " "
If itemContact.Firstname = "" Or itemContact.Firstname = " " _
Or itemContact.lastname = "" or itemContact.lastname = " " Then
itemContact.FileAs = itemContact.Company
itemContact.Save
end if
Next
Related
I have an Access form with a text box named Box1.
In this text box, I want to have the name of the last product in my table Products as the default value.
My table product has the fields: P_ID and P_Name.
I have coded in VBA in the form:
Me!Box1.DefaultValue = DLookup("P_Name", "Products", "P_ID = DMax("P_ID", "Products")")
However, there is an error in my code as the textbox displays #Name.
The DefaultValue property is a string, so quotes are needed:
Me!Box1.DefaultValue = "'" & DLookup("P_Name", "Products", "P_ID = " & DMax("P_ID", "Products") & "") & "'"
I am editing a database created by my predecessor at work. I am creating a "helper" textbox that will pull a value from a table in the same database.
Problem is, in my Dlookup, the name of the column that I am searching is also the name of the textbox on my form that contains the criteria. To change the name of my textbox, I would have to update a lot of code that I did not create. Is there a way around this?
txtgreigeweight = Application.DLookup("[GreigeWeightAvg]", "dbo_TuftingGreigeData", "GreigeRoll# = GreigeRoll#")
I expect the output to be the "GreigeWeightAvg" value from the table.
The output is:
"Syntax error (missing operator) in query expression 'GreigeRoll# = GreigeRoll#'."
Try to concatenate the value:
txtgreigeweight = Application.DLookup("[GreigeWeightAvg]", "dbo_TuftingGreigeData", "[GreigeRoll#] = " & Me![GreigeRoll#].Value & "")
or, it text:
txtgreigeweight = Application.DLookup("[GreigeWeightAvg]", "dbo_TuftingGreigeData", "[GreigeRoll#] = '" & Me![GreigeRoll#].Value & "'")
Include the fully-qualified control name in your selection criteria, e.g.:
txtgreigeweight = Application.DLookup("[GreigeWeightAvg]", "dbo_TuftingGreigeData", "GreigeRoll# = [Forms]![YourFormName]![GreigeRoll#]")
Change YourFormName as appropriate.
At first stop using special characters in field Names...some might think that it improves readability..BUT it won't...its almost a recipe for issues.
So ... just clarify what kind of value is GreigeRoll#
If its numeric (like 1,21,21321) then you should have :
txtgreigeweight = DLookup("[GreigeWeightAvg]", "dbo_TuftingGreigeData", "GreigeRoll# =" & [GreigeRoll#])
On the other hand is alphanumeric (like "A12", "BigGreige","1stG") then it should be :
txtgreigeweight = DLookup("[GreigeWeightAvg]", "dbo_TuftingGreigeData", "GreigeRoll# ='" & [GreigeRoll#] & "'")
I have a working code for creating a new AD user along with its distinct properties. The only thing I can't get to work is:
The users entry in the AD-Management window (caption) is the same as the CN. But I need the entry to be the same as the DisplayName attribute.
After manually changing the Name of the user entry, I found out, that the attribute 'name' changed as well.
(See screenshot)
Screenshot-1
So I tried using the attribute 'name' in my code as well.
But when I use the attribute during the first CommitChanges() (effectively creating the entitiy) it doesn't set to the Value I want it to be. Instead it stays the same as the login-name (SAMAccountName) of the user.
If I try to set the Value of the attribute during the later CommitChanges() it throws the following exception
"00002016: SvcErr: DSID-031A12D2, problem 5003 (WILL_NOT_PERFORM),
data 0" & vbLf
Do you have any Ideas what I can do to change the attribute 'name' of an AD-Object?
(BTW: My code contains some german words. Vorname = Given Name / Nachname = Surname etc. in case you're wondering)
Dim o As DirectoryEntry
Dim c As DirectoryEntries
Dim OUPath = ("LDAP://OU=" & OU & ",OU=Benutzer,DC=int,DC=xxxx,DC=xx")
o = New DirectoryEntry(OUPath, "xxxx", "xxxx", System.DirectoryServices.AuthenticationTypes.Secure)
c = o.Children()
o = c.Add("CN=" & UsernameV, "user")
o.Properties("SAMAccountName").Value = UsernameV
o.Properties("sn").Add(NachnameV)
o.Properties("givenName").Add(VornameV)
o.Properties("displayName").Add("" & NachnameV & ", " & VornameV & "")
o.Properties("name").Add("" & NachnameV & ", " & VornameV & "")
o.Properties("userPrincipalName").Add(UsernameV & "#xxxx")
o.CommitChanges()
o.Invoke("setPassword", New Object() {PWV})
o.CommitChanges()
'newUser.Properties("userAccountControl").Add(512)
'newUser.CommitChanges()
o.Properties("description").Add(UsernameV)
o.Properties("scriptPath").Add("logon.bat")
o.Properties("homeDrive").Add("H:")
o.Properties("homeDirectory").Add("\\datsrv-01\homes\" & UsernameV & "$")
o.Properties("company").Add(ComboBox_so.SelectedItem.ToString)
o.Properties("department").Add(ComboBox_abt.SelectedItem.ToString)
o.Properties("telephoneNumber").Add(TelV)
o.Properties("userAccountControl").Value = 65536
o.CommitChanges()
o.NativeObject.AccountDisabled = False
o.CommitChanges()
MsgBox("Erstellen erfolgreich")
I have some vba code on my form load that searches for the most recent record in a table then sets the default value for a field on the form to the value from that record.
The values are always in the format of 1484-002. The correct value is being found no problem but when it is displayed on the form it is 1482. This is leading me to believe that it is being treated as a formula and subtracting 2 from 1484 instead of displaying like a string.
The field in the table is set to short text. My form is bound to the table.
Here is a bit of my code:
Private Sub Form_Load()
Dim lastID as Integer
lastID = DMax("ID", "Drilling Detail")
Pattern.DefaultValue = DLookup("[Pattern]", "Drilling Detail", "[ID] = " & lastID)
How do I get the proper 1484-002 displayed?
Text values need delimiters. And maybe handle case of empty table.
Me.Pattern.DefaultValue = "'" & Nz(DLookup("Pattern", "Drilling Detail", "ID = " & Nz(DMax("ID", "Drilling Detail"),0)), "1484-001") & "'"
Can possibly eliminate the intermediate DMax() on the ID field and just DMax() Pattern.
If you really need to increase the sequence by 1:
Dim strNext As String
strNext = Nz(DMax("Pattern", "Drilling Detail"), "1484-000")
Me.Pattern.DefaultValue = "'" & Left(strNext, 5) & Format(Mid(strNext, 6) + 1, "000") & "'"
OnCurrent event is a better location if you need to increment the sequence for multiple records entry.
Advise not to use spaces in naming convention. Better would be DrillingDetail or Drilling_Detail.
Issue, where the character I am removing does not exist I get a blank string
Aim: To look for three characters in order and only get the characters to the left of the character I am looking for. However if the character does not exist then to do nothing.
Code:
Dim vleftString As String = File.Name
vleftString = Left(vleftString, InStr(vleftString, "-"))
vleftString = Left(vleftString, InStr(vleftString, "_"))
vleftString = Left(vleftString, InStr(vleftString, " "))
As a 'fix' I have done
Dim vleftString As String = File.Name
vleftString = Replace(vleftString, "-", " ")
vleftString = Replace(vleftString, "_", " ")
vleftString = Left(vleftString, InStr(vleftString, " "))
vleftString = Trim(vleftString)
Based on Left of a character in a string in vb.net
If File.Name is say 1_2.pdf it passes "-" and then works on line removing anything before "" (though not "" though I want it to)
When it hits the line for looking for anything left of space it then makes vleftString blank.
Since i'm not familiar (and avoid) the old VB functions here a .NET approach. I assume you want to remove the parts behind the separators "-", "_" and " ", then you can use this loop:
Dim fileName = "1_2.pdf".Trim() ' Trim used to show you the method, here nonsense
Dim name = Path.GetFileNameWithoutExtension(fileName).Trim()
For Each separator In {"-", "_", " "}
Dim index = name.IndexOf(separator)
If index >= 0 Then
name = name.Substring(0, index)
End If
Next
fileName = String.Format("{0}{1}", name, Path.GetExtension(fileName))
Result: "1.pdf"