• Force data entry (Acc 2000)

    Author
    Topic
    #386837

    Greetings,
    I have a main form called HouseHold and a subform called Applicants. For every HouseHold there can be more than one applicant (one-to-many relation). I

    Viewing 2 reply threads
    Author
    Replies
    • #672740

      Just a quick thought…
      Try to use this code in your subform control’s enter event property. When a user wants to enter the subform while he’s in a new record, it won’t be possible. As soon as he has entered some value in a main form control, he will gain access to the subform & the warning won’t show anymore:

      Private Sub subFrmCtlName_Enter()
      If Me.NewRecord Then
      MsgBox “Warning”
      ctlMain.SetFocus
      End If
      End Sub

      => subFrmCtlName = Name of the subform control on your form (NOT the name of the corresponding form object in the database window!)
      => CtlMain = the first control on your main form which should be filled with information first…

      I tried it for a second and realised you should also write some extra code to prevent the warning from occuring when the user starts a new record from within the subform (e.g. the pointer is in subform when user presses new record button). This could be done with something like:

      Private Sub Form_Current()
      if me.NewRecord then
      ctlMain.SetFocus
      end if
      End Sub

      I didn’t evaluate all possible side effects (e.g. instead of focussing on that specific main form control, it should be better if the focus could remain at the current control if it’s on the main form) but it might do. Though people with more experience in these matters might have some better/complementary suggestions,

      Hasse

    • #672821

      You can also take a look at the Orders form and its subform in the Northwind sample database that comes with Access.
      In the subform, the Form_Error event procedure is used to catch the error that occurs if the user tries to enter a record in the subform before a record in the main form has been entered. a warning is issued, the new record is canceled, and the focus is set back to the main form.

    • #672999

      I have similar types of data entry, in one case involving 3 tables. In all my databases I use specific Add forms populated with unbound text fields to collect the data I want to store. A Save button then invokes code which adds the data to tables. I use transactions to ensure that all tables are updated at the same time.

      This approach means that I can have all the error checking I need before actually committing the data and I don’t have to worry about partial saves.

    Viewing 2 reply threads
    Reply To: Force data entry (Acc 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: