Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    function for all forms (Access 2000)

    Function valid for all forms


    I have a function that is valid onl for the form ForderInformation.How can I rewrite it In order to be valid for all forms,regardless of the name of the form?

    The function is :


    Public Function deletearecord()
    Dim intAnswer As Integer
    intAnswer = MsgBox(" The product will be deleted. Are you sure ? ", vbQuestion + vbYesNo)
    If intAnswer = vbYes Then
    Dim f As Form
    Set f = [Forms]![FOrderinformation]![Forder details extended].[Form]
    Case 1
    f![stock].Value = f![stock].Value + f![cartons].Value
    f![items].Value = f![items].Value + f![Quantity].Value
    Case 2
    f![branch1].Value = f![branch1].Value + f![cartons].Value
    f![items1].Value = f![items1].Value + f![Quantity].Value
    Case 3
    f![branch2].Value = f![branch2].Value + f![cartons].Value
    f![items2].Value = f![items2].Value + f![Quantity].Value
    End If
    RunCommand acCmdDeleteRecord

    End Function

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: function for all forms (Access 2000)

    Rather than having your function in the form's code module, add a new module from the main Access window, under 'Modules' and put the function there. It should now have global scope.

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: function for all forms (Access 2000)

    Adam's answer is correct as to creating a public routine. To delete the current record in a form from an external routine, you have to pass arguments to the routine, including a way for it to know what form you're referring to, either a formname string or the form object itself as an object. In this case, the form is actually the subform object.

    From looking at your rough code, however, I see you want to do specific things in different subforms before you delete the record in that subform. Unless those are unbound fields, any value you stored in them would be deleted with the rest of the record, though. If they are unbound controls, that code is still more appropriate to the local form module, although the subform itself can be passed to an external routine to delete the specific record. I just don't see much point in exchanging a one line call to delete a record in a form module for a one line call to a public module to do the same thing.
    Charlotte

Posting Permissions

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