Results 1 to 5 of 5
  1. #1
    windwardmi's Avatar
    windwardmi is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Location
    NewJersey
    Posts
    46

    SaveIt ( ) on Click

    I want to put simple VB commands on buttons of a report.

    For instance I copied this for a button in another DB
    Private Sub cmdSave_Click()


    ' Put focus on "key" control
    Me.CompanyName.SetFocus
    ' Call the common save routine
    If Not SaveIt() Then Exit Sub
    End Sub
    and get this error message. what am I not correcting?

    Compile Error:
    Sub or Function not defined
    How do I define it to work?

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    What is the code for SaveIt and where do you have that code? Is it in a Standard Module?

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    in your other database there is likely a public function called saveit

    Look in your public functions for something that starts

    Function Saveit

    If you copy that code to your new database (assuming that it's using regular database functions) it should work in your new database. If it's doing something that is table/record specific it will likely not work unless you have an identical table structure in both databases.

  4. #4
    windwardmi's Avatar
    windwardmi is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Location
    NewJersey
    Posts
    46
    I found it defined in the Form itself in "General" as follows. But that still has further definitions needed. How can I simply define SaveIt ( )? I'm starting simple.

    Private Function SaveIt() As Integer
    Dim lngErr As Long, strError As String
    ' Common Save routine called from cmdSave and a couple of other places

    ' Default: We expect this to work
    SaveIt = True
    ' No need to do anything if the form isn't "dirty"
    If (Me.Dirty = True) Then
    ' OK, gonna try to save - set error trap
    On Error GoTo Save_Error
    Me.Dirty = False ' Force a save by resetting Dirty
    End If

    Save_Exit:
    Exit Function

    Save_Error:
    ' Got here if the save failed. Handle most common errors
    ' (Some may be handled by Form_Error instead)
    SaveIt = False ' Indicate save failed
    ' Try to analyze the error
    Select Case Err
    Case errCancel, errCancel2, errPropNotFound ' Cancel - ignore
    Resume Save_Exit
    Case errDuplicate ' Duplicate row - custom error message
    MsgBox "You're trying to add a record that already exists. " & _
    "Enter a new Company or click Cancel.", vbCritical, gstrAppTitle
    Case errInvalid, errInputMask
    ' Invalid data - custom error and log
    MsgBox "You have entered an invalid value. ", vbCritical, gstrAppTitle
    ErrorLog Me.Name & "_Save", Err, Error
    ' Field validation, Table validation, Custom Validation, End of Search, Spelling Check
    Case errValidation, errTableValidate, errCustomValidate, errSearchEnd, errSpellCheck
    ' Display the error
    ' All validation rules in the tables have custom error messages.
    MsgBox Error, vbCritical, gstrAppTitle
    Case Else
    ' Dunno - log and let error display
    ' Save the error code values because ErrorLog may get additional errors
    lngErr = Err
    strError = Error
    ErrorLog Me.Name & "_Save", lngErr, strError
    MsgBox "Error attempting to save: " & lngErr & " " & strError & Chr$(13) & Chr$(10) & "Try again or click Cancel to close without saving.", 48, gstrAppTitle
    End Select
    Resume Save_Exit
    End Function

  5. #5
    windwardmi's Avatar
    windwardmi is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2010
    Location
    NewJersey
    Posts
    46
    I found it led to module modUtility.

    Copied same in it's entirety and no errors.

    Learned there is no simple way to do this. I am learning by reverse engineering somewhat and that doesn't work.

    I will continue and try to learn how to write this code somehow.

    Thanks. Problem Solved for now.

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

Similar Threads

  1. On-Click Event Procedure
    By tbassngal in forum Forms
    Replies: 6
    Last Post: 07-20-2011, 07:06 AM
  2. Trying to click a button in vba
    By boywonder in forum Programming
    Replies: 8
    Last Post: 05-02-2011, 04:34 AM
  3. +1 on button click
    By 10 Gauge in forum Forms
    Replies: 4
    Last Post: 02-14-2011, 06:51 AM
  4. Can't Right Click Categories
    By netchie in forum Access
    Replies: 2
    Last Post: 10-26-2010, 10:48 AM
  5. Form on click
    By rexb in forum Forms
    Replies: 0
    Last Post: 11-16-2009, 08:49 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