PopUp box

  • Thread starter Thread starter Derek Brown
  • Start date Start date
D

Derek Brown

Hi all

I have a popup that I use simply to hold personal info. It only requires one
record so the popup is restricted to NoAdditions (records) Work brilliant
until you delete all the entries and close the form. Then when you reopen it
all of the controlls are invisible. Presumably this is because no data is
available and no records can be added. how do I set the form (in VBA) to
accept only one record.

Many thanks
 
In the popup form's Open event:

me.AllowAdditions = (dcount("*","PopupTable") = 0)

Rob
 
Derek,
As a simple solution, try setting...
AllowDeletions = No
AllowEdits = Yes
AllowAdditions = No

I created a little popup with just 2 fields and used this code to allow 1
record to be entered into the popup if none exists, but not allow any more
records to be added. The 1 record, can be deleted though, and the process
starts over again.
I didn't "wring" it out, but it should work the way you indicated in your
post.

Private Sub Form_Open(Cancel As Integer)
If DCount("[Field1]", "tblTest") = 0 Then 'Add a new record
AllowEdits = True
AllowAdditions = True
AllowDeletions = False
DoCmd.GoToRecord , , acNewRec
Else '
Disable Add a record
AllowEdits = True
AllowAdditions = False
AllowDeletions = True
End If
End Sub

Private Sub Field1_AfterUpdate()
AllowEdits = True
AllowAdditions = False
AllowDeletions = True
End Sub

Private Sub Field2_AfterUpdate()
AllowEdits = True
AllowAdditions = False
AllowDeletions = True
End Sub

hth
Al Camp
 
Rob,
On second look, I think there's a problem with your code.
Since the OnOpen event only fires once, if you add 1 record, you can also
add more... since your rule never gets tested again.

Given a popup with 1 field, with Add, Del, and Edit set to true...

On the AfterUpdate event of the 1 field...
Refresh
me.AllowAdditions = (dcount("*","PopupTable") = 0)
retests the Add/NotAdd condition.

Also, on the On Delete for the form...
DoCmd.Close
because since there is only one record... and the user doesn't want to edit
the existing record, might as well close the form.

Well, nuf' said about that eh?
Al Camp
 
Well spotted. It was after midnight, and I didn't really think about the
implications - merely answered the obvious question :-)

An alternative approach to using your After_Update code could be to include
the same code in the form's Current event.

Rob
 
Back
Top