Results 1 to 5 of 5
  1. #1
    AmanKaur123 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    47

    Code in a form after 'another form' is called from it doesn't work

    Hi Guys



    I have a form named 'FrmMain' and on the Add Button, the following code is written. Basically it will open up the 'Input form' and ask users to enter the password before the email gets sent to the Agent . And after this I want to export a template in the shared folder( For this ExportForm sub is called and it is written in the same form 'FrmMain') but unfortunately ExportForm code doesn't run and I don't want to paste ExportForm Sub code in the 'Input form' or in a module. This is because this is the pre written code to code the template in all the forms in my database. And I just need to add the functionality to enter password by the Supervisor before the email gets sent to the Agent.

    gPassKey,gAgent and gAgentName are global variable declared in a module. ExportForm sub is never called . Any help will be much appreciated.
    Code:
    Private Sub cmdAdd_Click()
    Dim rst As Recordset
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Dim sEmailCC As String
    Dim a As Boolean
    Dim Supref As Integer
    Dim FormRef As Integer
    FormRef = 24
    Me.txtHidden.SetFocus
    gRef = Me.txtAuditID
     
    gAgentName = cboAgent.Column(1)
    gAgent = Me.cboAgent
    If MsgBox("Do you wish to send this form to " & cboAgent.Column(1) & " to sign off?", vbQuestion + vbYesNo, "Send to Agent?") = vbYes Then
    DoCmd.OpenForm "frm_InputMask"
    Else
    gPassKey = False
    End If
    If gPassKey = True Then
    Call ExportForm
    End If
    Exit Sub
    The following code is written in 'Input Form':

    Code:
    Option Compare Database
    Private Sub cmdCancel_Click()
    If MsgBox("Are you sure you want to close the form without entering the Password?" & vbCr & vbCr & "If you choose to cancel then the Agent won't be notified that the form is ready to signoff.", vbInformation + vbYesNo, "Cancel ?") = vbYes Then
    DoCmd.Close acForm, Me.Name
    gPassKey = False
    Else
    Me.txtInput = ""
    gPassKey = False
    End If
    End Sub
    Private Sub cmdOK_Click()
    If StrComp(txtInput, DLookup("Passkey", "tbl_RMS_PassKey", "userID='" & NameofUser() & "'"), vbBinaryCompare) = 0 Then
    gPassKey = True
    Call Func_PassKey
    DoCmd.Close acForm, Me.Name
    Else
    MsgBox "Incorrect password.Please try again." & vbCr & vbCr & "If you don't remember the password then go to Create/Recover PassKey form on the home page and you will be able to get the password from there.", vbCritical + vbOKOnly
    Me.txtInput = ""
    Me.txtInput.SetFocus
    gPassKey = False
    End If
    End Sub

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    So it goes to the ExportForm code but something in there does not work? If so can you paste the code for ExportForm? Also when you say does not work, we need more info then that. And put a breakpoint in the fist code above and F8(step thru) the code to see where it is going and where it is failing.

  3. #3
    AmanKaur123 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    47
    Hi Bulzie, Instead of ExportForm Sub , lets use a message box saying "Hello" instead. I want the message to appear after 'Input form' is closed but at the moment the message appears just after Input Form is opened . Please see below. I don't want to copy the whole piece of code(ExportForm Sub) from 'frmmain' to 'InputForm' . Is there anyway this can be done in the frmmain?? Any help will be much appreciated.
    Code:
    Private Sub cmdAdd_Click()
    Dim rst As Recordset
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Dim sEmailCC As String
    Dim a As Boolean
    Dim Supref As Integer
    Dim FormRef As Integer
    FormRef = 24
    Me.txtHidden.SetFocus
    gRef = Me.txtAuditID
     
    gAgentName = cboAgent.Column(1)
    gAgent = Me.cboAgent
    If MsgBox("Do you wish to send this form to " & cboAgent.Column(1) & " to sign off?", vbQuestion + vbYesNo, "Send to Agent?") = vbYes Then
    DoCmd.OpenForm "frm_InputMask"
    Else
    gPassKey = False
    End If
    If gPassKey = True Then
    msgbox "Hello"
    End If
    Exit Sub

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    You don't have to copy all the code to frm_InputMask, just call the appropriate function = ExportForm() in the OnClose of frm_InputMask. I don't believe you can trigger something after that form closes in your code above becuase it does not stop when that form is opened, it will open the form and then continue with the code below that as you have noticed.

  5. #5
    AmanKaur123 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    47
    I found out something which worked great for me.
    Code:
    DoCmd.OpenForm "frm_InputMask", WindowMode:=acDialog

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

Similar Threads

  1. Replies: 8
    Last Post: 07-03-2015, 05:03 PM
  2. Can't Figure Out Why Code Doesn't Work
    By nosmoke in forum Programming
    Replies: 3
    Last Post: 09-26-2013, 12:23 PM
  3. Replies: 2
    Last Post: 11-17-2012, 06:03 PM
  4. My query code doesn't work
    By blacksaibot in forum Programming
    Replies: 2
    Last Post: 03-08-2012, 02:59 PM
  5. Query doesn't work when launched by code
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-24-2009, 09:52 AM

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