How To Stop A Form From Closing After Validating A Field

Jun 12, 2006

Hi,
I've got a close button on my form as follows:
Private Sub exitForm_Click()
DoCmd.Close
End Sub

In the beforeupdate event of the form I have have following code to validate the forms fields:

Private Sub Form_BeforeUpdate(Cancel As Integer)
'Place an asterisk (*) in the Tag Property of the text boxes you wish to validate.
'Then in the BeforeUpdate Event of the form, copy/paste the following:


Dim msg As String, Style As Integer, Title As String
Dim nl As String, ctl As Control


nl = vbNewLine & vbNewLine

For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If ctl.Tag = "*" And Trim(ctl & "") = "" Then
msg = "Data Required for '" & ctl.Name & "' field!" & nl & _
"You can't save this record until this data is provided!" & nl & _
"Enter the data and try again . . . "
Style = vbCritical + vbOKOnly
Title = "Required Data..."
MsgBox msg, Style, Title
ctl.SetFocus
Cancel = True
Exit For
End If
End If
Next
End Sub

This validation works fine up to a point. If I try to close the form and a required field is empty, I get a message box asking me to fill in the data. The problem is that when I click ok to the message, it shuts down the form, so I have to re-enter all the data again. My question is how do I prevent the form from closing after clicking ok on the message box?

appreciate your help:)

View Replies


ADVERTISEMENT

Stop Closing Form

Jul 25, 2007

Hi,
How can I stop user from closing the form if the mantory fields are not filled up? I try using gotocontrol but it is not working.

View 1 Replies View Related

How To Stop A Form From Closing If Some Essential Fields Are Not Populated

Mar 31, 2006

I tried putting the following code in the form unload procedure, but although it does generate the correct message, it doesnt stop the form from closing.

Private Sub Form_Unload(Cancel As Integer)
If [Starttime] > 0 And [Admin_time] = 0 Then
response = MsgBox("Please click on the stop button to stop the clock")
Exit Sub
End If
end sub

If the above condition holds, I want the user to click on the stop button before they close down the form. I'm guessing that the form is already commited to closing before the unload event? :o

View 5 Replies View Related

Forms :: Validating Text Field On Form Against Another Field In Same Record?

Apr 17, 2014

I have a form where I would like to validate (restrict) choices in subsequent fields.

Example

Combobox choices are Air, Fire, Water, Earth, Space

In the form I have 4 fields = Material1, Material2, Material3, Material4. (all in same record on my table)

Basically I need the validation to not allow duplicates across the 4 fields.

something like....

[Material1] <> [Material2] or [Material3]or [Material4]

I am not sure of the proper syntax for the validation field in the Form Properties. Or if I am even putting it in the right place.

View 3 Replies View Related

Validating A Field In Access

Oct 27, 2004

I have two tables in an Access Database- One is the chart of accounts, and the other is the actual entries, with the common field being ID. Chart of accounts is set up something like this-

ID Description
1000 Customer Revenue
2000 Office Expenses
2100 Paper

That kind of thing. Anyway, I want to set up the ID field in the entries table so that it is basically a pull down box that only allows you to enter one of the IDs listed in the Chart of Accounts. Any way to do this? I'd really hate to have to write a quick separate program to do this.

View 6 Replies View Related

Tables :: Validating A Field Using Another Checkbox Field

Apr 17, 2013

i have a database am working on in access 2010. I want a field to take its value based on another field's combo.Example;i have a checkbox field called "Loan" "Yes/No" and i have another textbox filed "Status" (which will hold eligibility). I want the Status to read Eligible when the checkbox is No and Non-eligible when its Yes

View 3 Replies View Related

Validating A Field (dependent Fields)

May 28, 2005

I am trying to put in a validation rule so that data in one field cannot be less than that in another.
e.g. i want to make a validation rule so that a phone call end time cannot be before the phone call start time.
Can anyone help???

View 5 Replies View Related

Comparing DB Entries Within A Field And Validating Them

Sep 25, 2005

Hi,

This may be a little difficult to explain but here goes:

I have a table in access 97 with the field Account. An account name is usually written as 0000000_A, but it MAY also have a secondary account and is usually written with the same first series of digits but ends in B e.g. 0000000_B. Therefore, we could have an account 0023654_A and 0023654_B.

Now for each account name there is another field called Items which are chosen from a combo box on a form (item 1, item 2, item 3, item 4, item 5, item 6, item 7 and item 8). An account may have more than one item.

Now if account B exists then it MUST contain the same entries as account A but can also have additional items.
So we could have a situation where:

0023654_A
item 1
item 2
item 3
item 4

0023654_B
item 1
item 2
item 3
item 4
item 5
item 6

Now what I am trying to implement is that if the core items (these are those that are contained in both - which would be item 1, item 2, item 3 and item 4 in the above example) are changed in either accounts making them not equal then a warning message should come up stating so. IT IS IMPERATIVE THAT THE CORE ITEMS ARE PRESENT IN BOTH.

I have some experience in Access 97, but unsure of how to tackle this. Could somebody please guide me ???

View 1 Replies View Related

Tables :: Validating Field - If Number Exist In Another Table?

May 1, 2013

Validating field from a query. I have a table with a field that has a value number that I need to validate that that number exist in another table in a field

Table1.field1 Number
Table2.field1 number

So let's say a have in table2.field1 the list 1 2 3 4 5 8

In table1.field1 I need to validate that the number I enter is present in table2.field1 so 1 would be ok but 6 invalid and it can't be a from list statement because I need the person to enter a number and get no error or get invalid number.

View 2 Replies View Related

Validating A Form Using VBA

Mar 23, 2006

Hi all

Im currently trying to set validation rules for a form using VBA, does anyone know of a good method of doing this as i'm a bit stuck:confused:

View 1 Replies View Related

Validating Primary Key Before Opening A New Form

Jan 4, 2006

Folks,

i have two forms with a command button on the first which opens the other...

is there a way of getting this button to validate the primary key (i.e. make sure its not a duplicate) before it trys to open the next form??

i've tried to call the next record function (as the button seems not allow the next record to continue) but all this has done is delete the record and open the new form rather than stopping the action...

any help much appreciated

cheers

si

View 4 Replies View Related

Validating A Form When Adding A Record

Oct 11, 2006

I have a form which allows an individual to add a cylinder record, i would like to validate the form in the sense that if the cylinder has already been added into the table it cannot be added again. So once the cylindernumber has been typed within the text field and the add button is clicked, the cylinder number typed is checked against the table if it has already been added a meesage should appear not allowing the user to enter a clyinder that is already added. I ahve tried this with the following code (the coding in red was already generated by adding a command button "add" to the form. The message i am recieving when the cylinder number in the textbox matches the cylinder number within the table is "you cant go to the specific record". I think my coding must be in the wrong order and IDEAS!!!!!

MyCode:
Private Sub Command39_Click()
On Error GoTo Err_Command39_Click

DoCmd.GoToRecord , , acNewRec


Exit_Command39_Click:
Exit Sub

Err_Command39_Click:
MsgBox Err.Description
Resume Exit_Command39_Click

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim StrSQl As String

Set db = CurrentDb

Set rs = db.OpenRecordset("SELECT * From tbl_CylinderMaster Where [Cylinder Serial Number] = '" & Me![Cylinder Serial Number] & "'")

If Me![Cylinder Serial Number] = [Cylinder Serial Number] Then
MsgBox ("This Cylinder Number has already been added please add another")

End If



End Sub

View 2 Replies View Related

Modules & VBA :: Validating Input In Combobox Of Form

Jan 24, 2015

I try to validate the input in a form combobox. In my table it works okay with a validation rule

validation rule: Like "[A][B]"
validation text: The input should be two numbers with A or B with two numbers Example: 01A01 or 21B43

But when i go to my form i can still input other letters than A or B. It will not save but there is no warning that the input is wrong.

View 4 Replies View Related

Memo Field - How To Stop Highlighting In Field

Aug 7, 2006

when i change records, my subform that has a memo field, shows the memo field data is "highlighted". i can make a mistake and hit any keyboard key and the memo field data will get erased.

is there a way to prevent such a problem?

if not, is there a work around. eg, hide the memo field until needed for more input? ideas on both issues?

View 1 Replies View Related

Return To Empty Field Before Closing

Aug 7, 2015

I have a form that requires a specific combo box selection completed prior to closing or it doesn't register the field ID# in the table or display the payment in the payment query. When I click on the accept button on the form, if [PaymentMethodID] is blank, I want to put up a msg box informing me to "choose a Payment Method", then return the cursor to [PaymentMethodID] field to allow the user to make the appropriate selection.How would I write that in VBA.

View 8 Replies View Related

How To Stop A Field In A Query Showing If It Is Empty

Jan 10, 2005

I'm trying to create a query which will only show fields that have information in them, but I can't figure out how to do it.

View 2 Replies View Related

Access Stop From Increasing Size Of A Key Field

Jul 24, 2013

Access stops me from increasing the size of a key field

Table tTrades
. Key field: idTrade: auto-number
. Field: Code: Text 10 characters

Table tData
. Key field: Code: Text 10 characters

I get an error message when I try to change either of these Code fields from size 10 to 16 characters

Error message - you cannot change the data type of field size. It is part of one or more relationships. Te change the data type of this field, first delete its relationships in the relationships window.

I deleted all relationships in the relationships window. But I still get the same error message.

If I click on relationship window > "All realtionships", Access reproduces all my relationships in the relationship window. Somehow it knows them. I deleted them all again and saved. But I still get the same error message.

I have a form ftTrades which generates automatically when I click on table tTrade and create a form.

I deleted this form ftTrades. But I still get the same error message.

How I can increase the size of this field.

View 3 Replies View Related

Stop Query On Null Value In Date Field

Jan 8, 2015

I have an append query that needs to stop if nothing is entered in the date field. What criteria should I use. Will is stop the query and continue?

View 4 Replies View Related

Forms :: How To Stop OpenArg Code When Field Is Already Populated

Sep 4, 2013

I have an order form that auto-populates details from the customer table into adderss and contact controls. But I don't want it to auto-populate when the underlying order table already has data in the related fields. Here is the code I use on Load form event...

======
Private Sub Form_Load()
'Use this version if the ID is a number
Dim x As Variant
Dim strControl As String
Dim lngID As Long
'If parameters exist, use them
If Len(Me.OpenArgs) > 0 Then

[Code] ....

View 2 Replies View Related

Modules & VBA :: ASCII And Sendkeys - Put Full Stop In The Field

Jan 15, 2015

I have a Combo box which contains a set of numbers divided by "."

e.g.: 1.342567.24433

When looking for a certain code, I would like to use the number pad to enter the first few e.g. 1.34 to move to the Position. In Previous Versions of Access I had a function on the key

If KeyAscii = 44 Then
DoCmd.CancelEvent 'stop the comma keypress being updated
SendKeys ".", True 'put a full stop in the field
End If

This worked fine, but in Access 7 and up, it turns off the number lock.

Is there an alternative to sendkeys to achieve the above or a way of directly turning the number lock on again?

View 3 Replies View Related

Forms :: Access 2010 - Opening New Form And Closing Current Form?

Mar 14, 2013

I am using Access 2010 - Version 14.0.61.29.5000 (32-bit)

I am building a custom Export Wizard to export data to Excel using the Report Wizard for the basic ideas.

All I am trying to do is have a [Back] button on a form to open another form and close the current form.

Private Sub cmdBack_Click()
DoCmd.OpenForm "frm_ExportWizardPage2", , , , , , Nz(Me.OpenArgs)
DoCmd.Close acForm, "frm_ExportWizardPage3"
End Sub

The new form is opening but then the current form is not closing. All forms are the same size, shape and positioned centrally although this should not make any difference.

Could this be anything to do with which form has the focus when I open the new form?

View 2 Replies View Related

Forms :: Stop Access From Creating New Record When Inputting Data In Field Or Tab

Dec 17, 2013

How do you prevent access from adding a new record when u input data in the current record or tab to the next field? My database is set up to open with a form where the user picks his name and then a week ending date once that is complete u open a new form where the name and date auto populate along with other fields to fill out such as job charge, charge type , times charged for each day of the week. But I don't want access to create a new record everytime the person inputs or tabs..... .

I have attached my database for better clarity!

View 9 Replies View Related

Forms :: How To Use Data On A Form When Running Code Before Closing The Form

Feb 4, 2014

I have a bound form with a few fields. I would like to run a sub after some of these fields are modified, but not others. I would like it to run only once, after user finishes his work on the form.

When using the Unload event - the form on the form is not there anymore (or did I get something wrong?).

Is there a way to trap Data on form just before the form closes?

View 4 Replies View Related

Closing A Form Vs. Really Closing A Form

Feb 17, 2005

This is related to some advice I received some time ago <a href="http://www.access-programmers.co.uk/forums/showthread.php?t=64818">here<a>

I am runnign some code, it performs some applications, then, if a Count Field is greater than 1, a form opens as a dialog, displaying some information:

Dim A As String
A = "NewForm"
If Me.[Count] > 0 Then
DoCmd.OpenForm A, acNormal, , , , acDialog
End If
If Me.Continue = "No" Then
Exit Sub

End If

The new form opens, and you can either view it, and click continue, which will run the rest of the code, or you can click quit, which updates Me.Continue to "No", and then it exits.

The problem is, when it exits the Sub, it doesn't really stop the code, it just leaves things kind of hanging. When I try to run the code again, I get:

3321 - The database engine could not lock the table 'NewTable' becuase it is already in use by another person or process.

Another symptom - The original form where I click to start running the code, has two date fields. Normally, when this form opens, they are blank, but when I exit the sub, as above, the previous dates I entered are still sitting there.

How can I make the forms really close?

View 2 Replies View Related

Closing A Form

Jul 14, 2005

When a form is open you can also see on the task bar that the form is open
If the user right clicks on the form(on the task bar ) they get the following options minimize , maximise , close.

Does any one know how I can stop the user selecting Close please ?

View 6 Replies View Related

Closing Of Form

Oct 11, 2006

when i close the form all the fileds in the forms gets saved to the table.
i want it should pop up before closing to save it or not.
i have a button on the form to save the fields in the table.
which has code

command23_Click()
DoCmd.GoToRecord , , acNewRec

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved