473,385 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. If Me.Dirty = False Then
  2.     MsgBox ("Please enter the details for this job."), vbExclamation, "Missing Data"
  3. ElseIf Me.Dirty = True Then
  4.         'Save new property details.
  5.         DoCmd.Save
  6.         DoCmd.Close acForm, "frm_newJob", acSaveYes
  7. 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
Expand|Select|Wrap|Line Numbers
  1. If Me.Details is null Then
  2.         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
Apr 24 '09 #1
1 5357
NeoPa
32,556 Expert Mod 16PB
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.
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 :
Expand|Select|Wrap|Line Numbers
  1. 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.
Apr 24 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Zaidan | last post by:
I am running Excel2000 under WIN98 2nd edition, and I am writing a VBA code (I will consider using javascript if I have to) that does the following, at the user command: 1- Start MS Explorer and...
0
by: Rachel Suddeth | last post by:
I have a tabbed ap, and I want to provide a message and give the user a chance to change there mind if they try to change tab pages in the middle of an update (otherwise just cancel the update and...
0
by: bj7lewis | last post by:
I have two modal dlg forms that are invoked(seperately) by a main form but the two modal dlg forms don't close when clicking the OK & Cancel buttons setup as below... Here the setup... //In...
0
by: Steve Kallal | last post by:
I have a DataGrid with an EditCommandColumn column set to a type of PushButton. I want to set set CssClass on these buttons and cannot without using code-behind code on the ItemDataBound event. The...
1
by: rn5a | last post by:
I want to create a custom control that encapsulates a Button & a TextBox. When the Button is clicked, the user is asked a question using JavaScript confirm (which shows 2 buttons - 'OK' &...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I change the confirm box to say yes/no or default to cancel?...
2
by: Matuag | last post by:
Hi All, I want to create following command buttons on a Form which users can edit. Save ( Save Changes made) Cancel ( Undo data changes) Exit ( Close form) I am using Macros for each of...
4
by: MaxMax | last post by:
I have a dialog box with a Cancel button that I want to be activable with the ESC key. In the form the Cancel button is connected to the CancelButton property. Now my problem is that the OnClick...
7
by: Terry Carroll | last post by:
I'm trying to use wx.ProgressBar, and the cancel button is not responding. Here is a simple program that exhibits the problem: ######################################################### import...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.