Results 1 to 9 of 9
  1. #1
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195

    Email Out Account Depending on PC Name

    Hi Guy's is there a method of changing email out account dependant on which machine and which user has logged in ?



    PC1 has got 2 accounts

    PC2 has got 3 accounts

    Db1 needs to use outaccount(2) on PC1
    Db1 needs to use outaccount(3) on PC2

    PC1 and db1

    I have got If me.User = "DM" Then me.txtOutAcc = "2" End IF
    (Now Changed the outaccount(2) to outaccount(Forms!frmMainMenu!txtOutAcc)
    This is fine

    PC2 and db1
    I have got If me.User = "SK" Then me.txtOutAcc = "3" End IF
    (Now Changed the outaccount(3) to outaccount(Forms!frmMainMenu!txtOutAcc)
    This is fine

    My hurdle is the following scenario

    If User SK Logs into PC1 and The txtOutAcc is going to be 3
    PC1 only has 2 accounts which can't work and comes up array index out of bounds due to only 2 accounts

    I hope i have explained this ok !!!!!!

    So i thought is there another criteria i can add in such as:

    my thought is:

    If me.user = SK Then
    If me.environ PC Name = PC1
    The me.txtOutAcc = "2"

    Then maybe i can keep the environ option all of the time
    If me.user = SK Then
    If me.environ PC Name = PC2
    The me.txtOutAcc = "3"

    Am i barking up the right or wrong tree ???

    Much appreciated

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Add the missing account to PC1?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Welshgasman as always thank you for your input, glad you understood the question as i was a little long winded explaining

    But that's a very simple answer i suppose, i will give that a go

    Do you know how to have the same 3 accounts in the same order ?

    ie:
    account1 Info@you
    account2 info@me
    account3 info@both

    Account 2 and 3 are in different order when selecting the from above the to line in outlook

    So PC1 account2 maybe account3 on PC2

    I would need them in the same order i guess ?

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    In my limited experience, they go in the order of the drop down, when you select an account?
    So if you give them the same names, they should be in the same order.?

    You could use this function in outlook to check?
    Code:
    Public Function ListEMailAccounts(AcctToUSe As String) As Integer
        Dim outApp As Object
        Dim i As Integer
        Dim AccNo As Integer
        Dim emailToSendTo As String
        
        Set outApp = CreateObject("Outlook.Application")
        'emailToSendTo = "xxxxx@gmail.com"                    'put required email address
        AccNo = 1
        'if smtp address=email we want to send to, acc no we are looking for is identified
        For i = 1 To outApp.Session.Accounts.Count
            'Uncomment the Debug.Print command to see all email addresses that belongs to you
    'Debug.Print "Acc name: " & OutApp.Session.Accounts.Item(i) & " Acc number: " & i & " , email: " & OutApp.Session.Accounts.Item(i).SmtpAddress
            'If OutApp.Session.Accounts.Item(i).SmtpAddress = emailToSendTo Then
            If outApp.Session.Accounts.Item(i).DisplayName = AcctToUSe Then
    
                AccNo = i
                Exit For
            End If
        Next i
        ListEMailAccounts = AccNo
        Set outApp = Nothing
    End Function
    Note the comments and amend to suit.

    HTH
    Last edited by orange; 06-06-2021 at 06:57 AM. Reason: edit as requested
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thank you, much appreciated

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    The underlying account index (1) (2) etc is quite arbitrary from my experience, so you have to loop through the available accounts to get to the correct one.
    I always thought the default account was (1) but got caught out by that assumption once as well.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Guy's thank you for your input, i went down welshgasmans idea so my way thats done it

    db1 = outacount 1 Any PC
    db2 = outacount 2 Any PC
    db3 = outacount 3 Any PC

    By using on db1 OnFormOpen, me.txtOutAcc = "1"
    By using on db2 OnFormOpen, me.txtOutAcc = "2"
    By using on db3 OnFormOpen, me.txtOutAcc = "3"

    Regardless of user name, I've got this working

    Thank you

  8. #8
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Just curious why use the account index and not the account name (email) when deciding which one to use. That way you wouldn't need to have all accounts on all PCs, as you know the user so just added the account name to the user table.
    https://www.rondebruin.nl/win/s1/outlook/account.htm

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  9. #9
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Vlad, that is better, i have adapted to that

    I have a different post coming up

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Emails Not Going Out From Account
    By DMT Dave in forum Access
    Replies: 5
    Last Post: 03-06-2021, 02:55 AM
  2. Replies: 2
    Last Post: 06-27-2018, 02:27 PM
  3. Replies: 6
    Last Post: 02-11-2015, 12:53 PM
  4. Replies: 5
    Last Post: 05-07-2014, 09:25 AM
  5. Getting one account from 15,000
    By citygov in forum Programming
    Replies: 4
    Last Post: 10-21-2011, 02:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums