OK & Cancel Buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Newbie23
    New Member
    • Jan 2009
    • 25

    OK & Cancel Buttons

    Hi All... yet another question : )

    I have a few forms for adding data where I have and OK cmd button and a Cancel cmd button. On the OK cmd button,if there has been no data added I would like a msgbox to appear (Please complete the job record... or something along those lines). The code I have is as follows:
    Code:
    If Me.Dirty = False Then
        MsgBox ("Please enter the details for this job."), vbExclamation, "Missing Data"
    ElseIf Me.Dirty = True Then
            'Save new property details.
            DoCmd.Save
            DoCmd.Close acForm, "frm_newJob", acSaveYes
    End If
    However the form saves and closes regardless. I think the problem is that the postcode field is automatically populated when the form loads, therefore the form is dirty from being loaded. So I tried
    Code:
    If Me.Details is null Then
            MsgBox ("Please enter the details for this job."), vbExclamation, "Missing Data" ....etc
    But then I get a Run Time error 424... Object Required

    Any Idea would be great, Many Thanks
    Jane
    Last edited by NeoPa; Apr 24 '09, 10:34 AM. Reason: Please use the [CODE] tags provided
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32653

    #2
    Where to start :
    1. Please remember to use the [ CODE ] tags when posting code.
    2. You should also Compile your code before posting questions. I quote below a short explanation. This saves us all some time.
    3. Re the first problem :
      When setting values for records, a useful technique is to set the Default property of a control, rather than changing the value as such. That way, the Dirty property is only set when a choice is made actually to enter data into the record.
    4. Re the second problem :
      This is where the compiler will help you.
      Functions may be called as subroutines, if you intend to ignore the return value. MsgBox() is a function. Parameters to a function are surrounded by parentheses (). Subroutines don't return values, and are generally called with a simple list of parameters following the subroutine name. NB. No parentheses. To ignore the value of a function (but still use the function calling syntax with the parentheses) simply place the function after the word "Call".

      The formats seem to be interchangeable within VBA. VBA doesn't care (It's a bit sloppy with its syntax checking sometimes).

      Another problem with your code is that your closing parenthesis ")" comes after only the first parameter. The other parameters appear after it.

    I hope this clears up these current problems for you Jane.
    Originally posted by NeoPa
    It is always a good idea to ensure that variable name checking is enabled, AND your code compiles (at least compilation has been attempted), before submitting a question.

    This avoids asking questions which are much more easily resolved on your own PC than on a forum.

    To ensure variable name checking is enabled for all new modules, go to - Tools / Options / Editor (from the VBA Editor window) and set Require Variable Declaration to True (checked). For existing modules, ensure that the Option lines at the very top include :
    Code:
    Option Explicit
    To compile your project, select (again from the VBA Editor window) Debug / Compile Project Name.

    We ARE generally happy to help with compilation problems too (If you find an error reported and you can't resolve it, let us know), but we do expect members to have tried compiling before submitting a question. That way we have a better idea of the sort of problem we're looking at.

    Comment

    Working...