Is it possible to make a script that allows sending email FROM:alias address including FROM:distribution address. I found a script that is only for FROM:alias address, but I didn't find a script for FROM:distribution address. The script is this:
Sub OnAcceptMessage(oClient, oMessage)
On Error Resume Next
If oClient.Username <> "" Then
If LCase(oClient.Username) <> LCase(oMessage.FromAddress) Then
Dim obBaseApp
Set obBaseApp = CreateObject("hMailServer.Application")
Call obBaseApp.Authenticate("Administrator","password") 'PUT HERE YOUR PASSWORD
StrClientDomain = Mid(oClient.Username,InStr(oClient.Username,"#") + 1)
StrFromDomain = Mid(oMessage.FromAddress,InStr(oMessage.FromAddress,"#") + 1)
Dim obDomain
Set obDomain = obBaseApp.Domains.ItemByName(StrClientDomain)
Dim obAliases
Dim obAlias
AliasFound = False
If LCase(StrClientDomain) <> LCase(StrFromDomain) Then
Set obAliases = obDomain.DomainAliases
For iAliases = 0 To (obAliases.Count - 1)
Set obAlias = obAliases.Item(iAliases)
if LCase(obAlias.AliasName) = LCase(StrFromDomain) Then
AliasFound = True
Exit For
End If
Next
If AliasFound Then
StrFromAddress = Left(oMessage.FromAddress, Len(oMessage.FromAddress) - Len(StrFromDomain)) + StrClientDomain
End If
Else
StrFromAddress = oMessage.FromAddress
AliasFound = True
End If
I found these variables for Distribution list in this code:
Sub OnAcceptMessage(oClient, oMessage)
Dim IsDistributionList : IsDistributionList = False
Dim Ogg, i, j, Recip, Dom, DomObj, DistListObj
For j = 0 to oMessage.Recipients.Count -1
Recip = oMessage.Recipients(j).OriginalAddress
Dom = (Split(Recip, "#"))(1)
Set DomObj = oApp.Domains.ItemByName(Dom)
If DomObj.DistributionLists.Count > 0 Then
For i = 0 To DomObj.DistributionLists.Count - 1
Set DistListObj = DomObj.DistributionLists.Item(i)
If Recip = DistListObj.Address Then
IsDistributionList = True
End If
Next
End If
Next
If IsDistributionList Then
Ogg = "[" & DistListObj.Address & "] "
Ogg = Ogg & oMessage.subject
oMessage.subject = Ogg
oMessage.Save
End If
End Sub
I wonder is it still possible to get Facebook user ID if I got 'only' the user's profile (profile username/link)?
For instance:
https://www.facebook.com/zuck
I've tried to do this with SDK and Graph API but it seems that all previous solutions don't work. Could you please give me a hint? I would like to go further but I'm not sure which way is correct.
You can do it with Excel. I put the macros that I use. You have to put the name in the first column and it will generate the id in the second column when you run the GenerateFaceIds macro. (You need to be logged into Facebook in IExplorer)
Sub GenerateFaceIds()
Dim total As Long
total = 1
Do Until IsEmpty(Cells(total, 1)) = True
If (Cells(total, 2) = "") Then
Call faceId(total)
End If
total = total + 1
Loop
MsgBox ("OK")
End Sub
Sub faceId(row As Long)
On Error GoTo ErrHandler
Dim appIE As Object
Set appIE = CreateObject("internetexplorer.application")
Dim id As String
id = Cells(row, 1)
With appIE
.Navigate "https://www.facebook.com/" + id
.Visible = False
End With
Do While appIE.Busy
DoEvents
Loop
Text = appIE.Document.Body.innerHTML
posinter = InStr(Text, "profile_owner")
profile_owner = Mid(Text, posinter + 16, 15)
posinter2 = InStr(profile_owner, """")
If posinter2 > 0 Then
profile_owner = Left(profile_owner, posinter2 - 1)
End If
Cells(row, 2) = profile_owner
appIE.Quit
Set appIE = Nothing
ExitSub:
Exit Sub
ErrHandler:
'MsgBox "Something's wrong"
appIE.Quit
Set appIE = Nothing
Resume ExitSub
Resume
End Sub
Result:
zuck 4
I'm trying hard to solve that issue without any luck :(
Here is my code :
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private frm As Form
Public Sub GenerateForm()
Set frm = New myForm
With frm
.Width = 4000
.Height = 3000
.Caption = "Message"
End With
frm.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
frm.Show vbModal
Sleep 3000
Unload Me
Set frm = Nothing
End Sub
Private Sub Command1_Click()
GenerateForm
End Sub
I want to close the newly created form automatically after 3 seconds.
Windows opened in modal mode wait for user input, so the statements after
frm.Show vbModal
will not execute.
.
You have two solutions:
a) remove vbModal
b) add Timer on myForm and set Interval to 1000 (mean 1 second), next add this code in Timer event:
Private Sub Timer1_Timer()
Static sec As Integer
sec = sec + 1
If sec >= 3 Then
Timer1.Enabled = False
Unload Me
End If
End Sub
Last, you should use
Unload frm
since Unload Me is wrong.
You could use the timer like this, once it reaches 3 seconds (3000) it will close the form and open another one.
Private Sub Timer1_Timer()
If Timer1.Interval = 3000 Then
frm_Menu.Show
Unload frmSplash
Timer1.Enabled = False
End If
End Sub
I am somewhat new to vba, and I'm trying to create a somewhat more complex conditional format than access 2013 allows from the conditional formatting menu. I have a form with 22 target date and actual date fields. for each pair I need to:
if the target date is more than 7 days in the future, color it green.
If the target date is less than 7 days in the future or is today, color it yellow
If the target date in the past, color it red.
UNLESS there is an actual date it was accomplished, in which case:
If the actual date is before the target date, color both dates green
If the actual date is after the target date, color both dates red.
Because I have to do this on form load, and on the change of any date field (the target dates are calculated, but will change if other data is changed in the form), I wanted to write a public sub that takes form name, target date, and actual date as variables. I was able to code each box to do this on the local form module with 'Me.txtbox'
However, when I try to reference the form and text boxes from the public sub, it seems like I'm not properly referencing the text boxes on the form. I've tried 3 or 4 different ways of doing this (string, textbox.name, etc) and I feel like I'm close, but ...
Code that works as desired in the form module
Private Sub txtFreqReqDate_AfterUpdate()
If Me.txtFreqReqDate <= Me.txtFreqReq Then
Me.txtFreqReq.Format = "mm/dd/yyyy[green]"
Me.txtFreqReqDate.Format = "mm/dd/yyyy[green]"
ElseIf Me.txtFreqReqDate > Me.txtFreqReq Then
Me.txtFreqReq.Format = "mm/dd/yyyy[red]"
Me.txtFreqReqDate.Format = "mm/dd/yyyy[red]"
ElseIf IsNull(Me.txtFreReqDate) = True Then
If Me.txtFreqReq < Now() Then
Me.txtFreqReq.Format = "mm/dd/yyyy[red]"
ElseIf Me.txtFreqReq >= (Now()+7) Then
Me.txtFreqReq.Format = "mm/dd/yyyy[yellow]"
ElseIf Me.txtFreqReq > (Now()+7) Then
Me.txtFreqReq.Format = "mm/dd/yyyy[green]"
Else
Me.txtFreqReq.Format = "mm/dd/yyyy[black]"
End If
Else
Exit Sub
End If
End Sub
Perhaps not the prettiest, but I'm always open to constructive criticism. I'd have to write this 22+ times for each pair, changing the name of the text boxes each time. I want to write a public sub that just takes the names of the text boxes, but I can't seem to find the right combination:
Private Sub txtFreqReqDate_AfterUpdate()
FormatBoxes(Me, me.txtFreqReqDate, me.txtFreqReq)
End Sub
And in another module:
Public Sub FormatBoxes(CurrentForm As Form, txtActual as Textbox, txtTarget as Textbox)
frmName = CurrentForm.name
tbActual = txtActual.Name
tbTarget = txtTarget.Name
If frmName.tbActual <= frmName.tbTarget Then
frmName.tbTarget.Format = "mm/dd/yyyy[green]"
frmName.tbActual.Format = "mm/dd/yyyy[green]"
ElseIf frmName.tbActual > frmName.tbTarget Then
frmName.tbTarget.Format = "mm/dd/yyyy[red]"
frmName.tbActual.Format = "mm/dd/yyyy[red]"
ElseIf IsNull(frmName.tbActual) = True Then
If frmName.tbTarget < Now() Then
frmName.tbTarget.Format = "mm/dd/yyyy[red]"
ElseIf frmName.tbTarget >= (Now()+7) Then
frmName.tbTarget.Format = "mm/dd/yyyy[yellow]"
ElseIf frmName.tbTarget > (Now()+7) Then
frmName.tbTarget.Format = "mm/dd/yyyy[green]"
Else
frmName.tbTarget.Format = "mm/dd/yyyy[black]"
End If
Else
Exit Sub
End If
End Sub
Sorry if this is a bit long, I'm just at my wit's end...
Also, apologies for any typos. I had to re-type this from another machine.
You can simply use the textbox parameters directly in your sub.
It is not even necessary to pass the form as parameter.
Public Sub FormatBoxes(txtActual as Textbox, txtTarget as Textbox)
If txtActual.Value <= txtTarget.Value Then
txtTarget.Format = "mm/dd/yyyy[green]"
etc.
Note that when calling it, you need either Call or remove the parentheses.
Private Sub txtFreqReqDate_AfterUpdate()
Call FormatBoxes(me.txtFreqReqDate, me.txtFreqReq)
' or
' FormatBoxes me.txtFreqReqDate, me.txtFreqReq
End Sub
CurrentForm.name is a string. It is the Name property of the CurrentForm object. The CurrentForm object also has a controls collection in which the texboxes live. You can refer to them by name in there like CurrentForm.Controls("tbTarget") but you can also say CurrentForm.tbTarget. So you're very close and on the right track.
Change
frmName = CurrentForm.name
tbActual = txtActual.Name
tbTarget = txtTarget.Name
to
set frmName = CurrentForm
if frmName is not nothing then
set tbActual = txtActual
set tbTarget = txtTarget
end if
Alternatively if your signature on your method is
Public Sub FormatBoxes(CurrentForm As string, txtActual as string, txtTarget as string)
then your set up will look like
set frmName = forms(CurrentForm)
if frmName is not nothing then
set tbActual = frmName.controls(txtActual)
set tbTarget = frmName.controls(txtTarget)
end if
But I think the first one will work better.
I wanted to post the finished code to help out anyone else who searches for this subject. I did a couple thins to make this sub more universal.
First, Instead of using the date format, I only changed the .ForeColor, allowing me to use this sub for any type of textbox.
Public Sub FormatBoxes(txtActual As TextBox, txtTarget As TextBox, chkRequired As CheckBox, _
Optional intOption as Integer)
Dim intRed As Long, intYellow As Long, intGreen As Long, inBlack As Long, intGray As Long
intBlack = RGB(0, 0, 0)
intGray = RGB(180, 180, 180)
intGreen = RGB (30, 120, 30)
intYellow = RGB(217, 167, 25)
intRed = RGB(255, 0, 0)
If (chkRequired = False) Then
txtTarget.ForeColor = intGray
txtActual.ForeColor = intGray
If intOption <> 1 Then
txtTarget.Enabled = False
txtActual.Enabled = False
txtTarget.TabStop = False
txtActual.TabStop = False
End If
Else
If intOption <> 1 Then
txtTarget.Enabled = True
txtActual.Enabled = True
txtTarget.Locked = True
txtActual.Locked = False
txtTarget.TabStop = False
txtActual.TabStop = True
End If
If IsBlank(txtActual) = True Then
If txtTarget < Now() Then
txtTarget.ForeColor = intRed
ElseIf txtTarget > (Now() + 7) Then
txtTarget.ForeColor = intGreen
ElseIf txtTarget >= Now() And txtTarget <= (Now() +7) Then
txtTarget.ForeColor = intYellow
Else
txtTarget.ForeColor = intBlack
End If
ElseIf intOption - 1 Then
txtTarget.ForeColor = intBlack
txtActual.ForeColor = intBlack
ElseIf txtActual <= txtTarget Then
txtTarget.ForeColor = intGreen
txtActual.ForeColor = intGreen
ElseIf txtActual > txtTarget Then
txtTarget.ForeColor = intRed
txtActual.ForeColor = intRed
End If
End If
End Sub
In case you were wondering, IsBlank() is a function that checks for a null or zero length string:
Public Function IsBlank(str_in As Variant) As Long
If Len(str_in & "") = 0 Then
IsBlank = -1
Else
IsBlank = 0
End If
End Function
Thanks for all the help, and I hope this is useful for someone.
I have a small program for some college coursework, i have to enter data of the gender and age of a group of people then work out the male and female percent and the child and adult percent. The bit i am stuck with is i want to display my results on labels on a separate form. Here is my code:
Public Class Form1
Dim TotalGender As Integer
Dim TotalAge As Integer
Dim MaleCount As Integer
Dim FemaleCount As Integer
Dim ChildCount As Integer
Dim AdultCount As Integer
Dim MalePercent As Single
Dim FemalePercent As Single
Dim AdultPercent As Single
Dim ChildPercent As Single
Private Sub btnSub_Click(sender As Object, e As EventArgs) Handles btnSub.Click
If cmbGender.Text = "Male" Then
MaleCount += 1
End If
If cmbGender.Text = "Female" Then
FemaleCount += 1
End If
If cmbAge.Text > 18 Then
ChildCount += 1
End If
If cmbAge.Text <= 18 Then
AdultCount += 1
End If
End Sub
Private Sub btnResults_Click(sender As Object, e As EventArgs) Handles btnResults.Click
Form2.Show()
MalePercent = MaleCount / TotalGender * 100
FemalePercent = FemaleCount / TotalGender * 100
AdultPercent = AdultCount / TotalAge * 100
ChildPercent = ChildCount / TotalAge * 100
End Sub
Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
TotalGender = 0
TotalAge = 0
MaleCount = 0
FemaleCount = 0
ChildCount = 0
AdultCount = 0
MalePercent = 0
FemalePercent = 0
AdultPercent = 0
ChildPercent = 0
End Sub
End Class
My second form has all the labels already placed and i know how to display results on a label, i just don't know how to transfer the results across to another form
You can write on form 1 .It shows your results on form2
Form2.Label1.Text = AdultCount
Form2.Show()