+ Reply to Thread
Results 1 to 7 of 7

get functions in a submit button.

Hybrid View

  1. #1
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: How do i get these functions in a submit button.

    Hello briant97,

    Assuming all the code you post resides in a VBA module in your project, add the calls to the click event for the submit button. It would help top know what type of button you are using: Forms or Control Toolbox.

    For Example
    Private Sub CommandButton1_Click()
      SaveName
      SendEmail
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  2. #2
    Registered User
    Join Date
    12-24-2009
    Location
    Texas
    MS-Off Ver
    2019
    Posts
    16

    Re: get functions in a submit button.

    I went to insert and to form control. When I click submit I get Cannot run the macro "SSR.xls!Submit'. The Macro may not be available in this workbook or all macros my be disabled.

  3. #3
    Registered User
    Join Date
    12-24-2009
    Location
    Texas
    MS-Off Ver
    2019
    Posts
    16

    Re: get functions in a submit button.

    Below is the code that I have.

    Option Explicit
     'Disable Save and SaveAs
    Dim flg As Boolean
    
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
        If flg Then MsgBox "The 'Save and Save As' function has been disabled." & Chr(10) & "Only 'Submit Button' will work.", vbInformation, "Save and Save As Disabled"
    Cancel = True
    End Sub
    
    Private Sub Workbook_Open()
        flg = True
        Dim x As String
        
        If Me.Name <> "SSR.xls" Then Exit Sub
         
        On Error GoTo ErrorHandler
    One:
        Open "\\server\sharename\Forms\" & ThisWorkbook.Name & _
        " Counter.txt" For Input As #1
        Input #1, x
        Close #1
        x = x + 1
         
    Two:
         '******THIS LINE IS OPTIONAL******
        Sheets(1).Range("A1").Value = x
         '********************************
        Open "\\server\sharename\Forms\" & ThisWorkbook.Name & _
        " Counter.txt" For Output As #1
        Write #1, x
        Close #1
         
        Exit Sub
         
    ErrorHandler:
        Select Case Err.Number
             
        Case 53 'If Counter file does not exist...
    NumberRequired:
            x = InputBox("Enter a Number greater than " & _
            "zero to Begin Counting With", _
            "Create '\\server\sharename\Forms\" & ThisWorkbook.Name & _
            " Counter.txt' File")
            If Not IsNumeric(x) Then GoTo NumberRequired
            If x <= 0 Then GoTo NumberRequired
            Resume Two
        Case Else
            Resume Next
        End Select
        
    End Sub
    
    Private Sub CommandButton1_Click()
    
    
    Sub Save_File()
    
    Dim SaveName As String
           SaveName = ActiveSheet.Range("A1").Text
           ActiveWorkbook.SaveAs Filename:="\\server\sharename\forms\" & _
           SaveName & ".xls"
    End Sub
    
    'Will Email Document
    
    Sub SendMail1()
    
       
        'need a reference to MS Outlook object library
       
        Dim olFolder As Outlook.MAPIFolder
        Dim olMailItem As Outlook.MailItem
        Dim olContact As Outlook.Recipient
        Dim r, ToContact
       
        Set olFolder = GetObject("", _
            "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
        For r = 1 To LastRow(ActiveSheet)
            If Trim(ActiveSheet.Cells(r, 1)) <> "" Then
                Set olMailItem = olFolder.Items.Add ' creates a new e-mail message
                With olMailItem
                    .Subject = "KCI SSR has been created file link enclosed" ' message subject
                    Set olContact = .Recipients.Add(ActiveSheet.Cells(2, 1)) ' add To recip
                    If Trim(ActiveSheet.Cells(r, 2)) <> "" Then    'set up cc if email address available
                          Set olContact = .Recipients.Add(ActiveSheet.Cells(r, 2)) ' add cc recipient
                          olContact.Type = olCC ' set latest recipient as CC
                    End If
                    .Body = " SSR has been created to view/edit please click following link " & ActiveSheet.Cells(1, 3) & vbCrLf & vbCrLf & "Regards" & vbCrLf & "IT"
                    .Send ' sends the e-mail message (puts it in the Outbox)
                End With
                Set ToContact = Nothing
                Set olMailItem = Nothing
            End If
           
        Next r
        Set olFolder = Nothing
    End Sub
    
    Function LastRow(ws As Worksheet) As Single
    
        'uses worksheet object
        'returns last used row
     
        On Error Resume Next
       
        With ws
          LastRow = .Cells.Find(What:="*", _
            SearchDirection:=xlPrevious, _
            SearchOrder:=xlByRows).Row
        End With
     
    End Function
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1