Problem with "Close" Button

  • Thread starter Thread starter tom
  • Start date Start date
T

tom

This is a database designed to be used by a data entry person. I plan
on eliminating the normal navigation buttons on the menu bar so that
the only button that appears to the data entry person is a "Close"
Button.
The problem that I'm having is that the "Close" button will not
function the same way as the record advance button does on the
standard menu bar.

The Form is designed to prevent duplicate dates from being entered. I
accomplished this by adding indexing and no duplicates to the date
field. When advancing to the next record with the menu bar everything
works fine (A message pops up telling the user that there is a problem
with the date.) However, when using the Close button, the Form
closes, it doesn't save the record BUT it doesn't notify the user
there was a problem. I am SO NEW to this, I've never done ANYTHING in
VBA but I read thru this forum and found the exact same problem
described and a solution. However the solution I believe has some
syntax errors and maybe even some logic I don't want. Anyhow I can't
get it to work at all because of syntax problems. Can anyone help?
Here is the code below. The first part of the IF statment seems just
what I want to do, however the ELSE part of the statement I'm not
sure. All I want it to do, if the date is NOT duplicated is to
advance to the next field. Sigh..... any help would be appreciated.

If DCount("[IndexedFieldName]", "TableName") > 1 then

msgbox "Duplicate entry. Record will not be saved."
undo the current record

else

save the record
close the form
 
Put the following code in the Unload event of the form:

If DCount("[IndexedFieldName]", "TableName") > 1 then
MsgBox "Indexed Field name is a duplicate. Change the value."
Cancel = True
Me![IndexedFieldname].SetFocus
End If
 
Thanks for the help! I placed the code below and it "almost" works.
When a duplicate date has been entered and the Close button is
clicked, the form does reject this entry and the message box pops up
notifying the user of a duplicate date. However, when you click on
"OK" in the message box it generates a run time error #2169 and ask
the user to end or debug. Can someone help me get past this error?

PC Datasheet said:
Put the following code in the Unload event of the form:

If DCount("[IndexedFieldName]", "TableName") > 1 then
MsgBox "Indexed Field name is a duplicate. Change the value."
Cancel = True
Me![IndexedFieldname].SetFocus
End If

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com


tom said:
This is a database designed to be used by a data entry person. I plan
on eliminating the normal navigation buttons on the menu bar so that
the only button that appears to the data entry person is a "Close"
Button.
The problem that I'm having is that the "Close" button will not
function the same way as the record advance button does on the
standard menu bar.

The Form is designed to prevent duplicate dates from being entered. I
accomplished this by adding indexing and no duplicates to the date
field. When advancing to the next record with the menu bar everything
works fine (A message pops up telling the user that there is a problem
with the date.) However, when using the Close button, the Form
closes, it doesn't save the record BUT it doesn't notify the user
there was a problem. I am SO NEW to this, I've never done ANYTHING in
VBA but I read thru this forum and found the exact same problem
described and a solution. However the solution I believe has some
syntax errors and maybe even some logic I don't want. Anyhow I can't
get it to work at all because of syntax problems. Can anyone help?
Here is the code below. The first part of the IF statment seems just
what I want to do, however the ELSE part of the statement I'm not
sure. All I want it to do, if the date is NOT duplicated is to
advance to the next field. Sigh..... any help would be appreciated.

If DCount("[IndexedFieldName]", "TableName") > 1 then

msgbox "Duplicate entry. Record will not be saved."
undo the current record

else

save the record
close the form
 
Back
Top