Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2010
    Posts
    102
    Provided Answers: 6

    Unhappy Answered: Retrieving value from underlying form

    Hi All

    I've been struggling to get this to work and the various posts that I've seen/read haven't enabled me to solve the problem. I know that it is simple but it is eluding me.

    I have a form called Customer Information that has a field ServContactEmail

    On this form I have a button that opens another form, frmChooseEmailTemplate, that allows the user to choose one of three emails to be sent to ServContactEmail by clicking on the appropriate button. The buttons simply assign the email template name to call.

    I can get everything to work but can't figure out how to get the ServContactEmail field from the Customer Information form in to the frmChooseEmailTemplate form so that it automatically puts ServContactEmail in to the To field of the email.

    I've tried all sorts of approaches but haven't been able to get it to work and is frankly driving me crazy.

    Could one of you kind guru's point me in the right direction please.

  2. Best Answer
    Posted by sheusz

    "OK, So I got it sorted once I read up more on OpenArgs. This now works.

    Code:
    Private Sub btnChooseServTemplate_Click()
    On Error GoTo Err_btnChooseServTemplate_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "frmChooseEmailTemplate"
        DoCmd.OpenForm stDocName, OpenArgs:=Me.ServContactEmail
          
    Exit_btnChooseServTemplate_Click:
        Exit Sub
    
    Err_btnChooseServTemplate_Click:
        MsgBox Err.Description
        Resume Exit_btnChooseServTemplate_Click
        
    End Sub


    Turns out the other problem was that I needed to declare a public variable used in my email routine because the email sub was being called from another sub.

    I then made the public variable = OpenArgs and all is well. (this code place in the OnOpen property of the form

    Code:
    Option Compare Database
    Public EmailAddr As String
    Code:
    Private Sub btnServiceEmail_Click()
      EmailAddr = Me.OpenArgs
        DoCmd.Close
        Call SendMailServ
        
    End Sub
    Maybe it could be a little tidier and efficient, so I'm open to comments."


  3. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,482
    Provided Answers: 11
    one way

    Why use the OpenArgs

    DoCmd.OpenForm "frmChooseEmailTemplate", , , , , , thisistheOpenArgs
    hope this help

    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.
    DONT WORRY ABOUT THOSE WHO TALK BEHIND YOUR BACK
    THEY'RE BEHIND YOU FOR A REASON

  4. #3
    Join Date
    Sep 2010
    Posts
    102
    Provided Answers: 6
    Hello Myle

    Thanks for the reply. OpenArgs is one of the methods I chose that seems to be the best and most popular, however I'm obviously doing something wrong, probably in the way I'm using the command.

    This is the code I'm using on the OnClick command of the button.

    Code:
    Private Sub btnChooseServTemplate_Click()
    On Error GoTo Err_btnChooseServTemplate_Click
    
        Dim stDocName As String
    
        stDocName = "frmChooseEmailTemplate"
    
        DoCmd.OpenForm stDocName, OpenArgs:=txtServContactEmail
    
    Exit_btnChooseServTemplate_Click:
        Exit Sub
    
    Err_btnChooseServTemplate_Click:
        MsgBox Err.Description
        Resume Exit_btnChooseServTemplate_Click
        
    End Sub
    Using this code the email template opens but the .To field is blank (I know that this part works perfectly because I use it elsewhere in my DB)

    As I said it's probably syntax, but I can't seem to sort it out.

  5. #4
    Join Date
    Sep 2010
    Posts
    102
    Provided Answers: 6
    OK, So I got it sorted once I read up more on OpenArgs. This now works.

    Code:
    Private Sub btnChooseServTemplate_Click()
    On Error GoTo Err_btnChooseServTemplate_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "frmChooseEmailTemplate"
        DoCmd.OpenForm stDocName, OpenArgs:=Me.ServContactEmail
          
    Exit_btnChooseServTemplate_Click:
        Exit Sub
    
    Err_btnChooseServTemplate_Click:
        MsgBox Err.Description
        Resume Exit_btnChooseServTemplate_Click
        
    End Sub


    Turns out the other problem was that I needed to declare a public variable used in my email routine because the email sub was being called from another sub.

    I then made the public variable = OpenArgs and all is well. (this code place in the OnOpen property of the form

    Code:
    Option Compare Database
    Public EmailAddr As String
    Code:
    Private Sub btnServiceEmail_Click()
      EmailAddr = Me.OpenArgs
        DoCmd.Close
        Call SendMailServ
        
    End Sub
    Maybe it could be a little tidier and efficient, so I'm open to comments.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •