Use unbound controls to edit bound continuous form (1 Viewer)

foshizzle

Registered User.
Local time
Today, 09:31
Joined
Nov 27, 2013
Messages
277
I have a form with two subforms; one in the header and another in the detail area of the main form.
The header (form) is used for data entry and contains all unbound controls. The detail (form) has bound controls in continuous view with an Edit button at the end of each record row.

Problem:
I would normally use bound controls in the header but this time I have to use unbound controls to prevent new data entry into a table before the record is ready to be saved. So, I am unsure how to make the contents of a record populate the unbound controls in the header when the user clicks the Edit button for that specific record.

A copy of the database is included for reference. Thanks in advance!
 

Attachments

  • myBD2.accdb
    816 KB · Views: 94

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:31
Joined
May 21, 2018
Messages
8,516
I have to use unbound controls to prevent new data entry into a table before the record is ready to be saved.
That is not true. You can definitely validated all new data prior to saving. This is done in the before update, and is pretty routine.
 

foshizzle

Registered User.
Local time
Today, 09:31
Joined
Nov 27, 2013
Messages
277
That is not true. You can definitely validated all new data prior to saving. This is done in the before update, and is pretty routine.

I should clarify: I could not get this particular entry form to work using bound controls. Here is the link to this particular thread. Thank you
Reset combobox if user clicks another form
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:31
Joined
May 21, 2018
Messages
8,516
Not sure this answers your question, but you can link a subform to an unbound control. (or in fact any value)
example. A combo in the main form that returns an employee id but it is unbound and the subform has an employee id foreign key

masterlinkfields: [cmboEmployee]
Childlinkfields: [employeeID_FK]
 

foshizzle

Registered User.
Local time
Today, 09:31
Joined
Nov 27, 2013
Messages
277
Not sure this answers your question, but you can link a subform to an unbound control. (or in fact any value)
example. A combo in the main form that returns an employee id but it is unbound and the subform has an employee id foreign key

masterlinkfields: [cmboEmployee]
Childlinkfields: [employeeID_FK]

Where would I find those link fields/which would be the proper form? The main for, header form or detail form?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:31
Joined
May 21, 2018
Messages
8,516
To make this a lot easier since your main form is actually a subform. I added a textbox on the main form. You can hide this once you get how it works. I link to that textbox. See subform control. I update that textbox in the combos afterupdate.
 

Attachments

  • MajP_myBD2.accdb
    1.3 MB · Views: 99

foshizzle

Registered User.
Local time
Today, 09:31
Joined
Nov 27, 2013
Messages
277
I suppose I could also just use one main form and a separate continuous form in the main form's detail section? I just couldnt get that working (couldn't figure out the references). I'm asking because I actually have a separate unbound text box on my header form (which is a sub form) which links to the combobox's after update event. Or would this not be the same thing? What is the proper way of doing this?
Code:
 Me.txtTruckNumber = Me.cboTruckNumber
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:31
Joined
May 21, 2018
Messages
8,516
not sure of your question. I made it a form with a subform and linked to the combo.
 

Attachments

  • MajP_myBD3.accdb
    1.3 MB · Views: 94

foshizzle

Registered User.
Local time
Today, 09:31
Joined
Nov 27, 2013
Messages
277
Nice, thank you I was just working on that. Except im not really needing to filter the continuous form below. The combobox is for two reasons: 1. Choose a truck for new data entry. 2. To populate the unbound controls labeled as "previous" in the header.

The other idea of the form is to be able to edit a record in the subform by clicking it's Edit button. The Edit button would normally populate the remainder of the header controls (for editing) but since they are now unbound, I'm just not sure how to make that happen.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:31
Joined
May 21, 2018
Messages
8,516
I cannot figure out what you are doing? Why is the previous record not the last record, but the second to last? What do you do with that once you populate it. I still think if this was bound it would make more sense. It seems to be like a split form where the header would be a subform in single view and the list below.
 

foshizzle

Registered User.
Local time
Today, 09:31
Joined
Nov 27, 2013
Messages
277
Try this one; this is back to the way I had it yesterday except using one main form and one subform in the header. The combobox correctly populates the controls in the header and saves. However I'm back to the original issue which I never resolved which is:
After any data is entered, or you hit the reset button to clear the form for a new record, I receive the message "the Microsoft Access database engine cannot find a record in the table 'tblTrucks' with key matching field(s) 'TruckNumberLookup;. Also attached a clip of the relationship
 

Attachments

  • myDb2.accdb
    1.5 MB · Views: 106
  • relationship.jpg
    relationship.jpg
    98.7 KB · Views: 98

foshizzle

Registered User.
Local time
Today, 09:31
Joined
Nov 27, 2013
Messages
277
Disregard; I've also spoken with the users and was able to remove the calculated controls. So, I've got this working now using one main form and one subform. Thanks for your help
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 09:31
Joined
Feb 19, 2002
Messages
43,196
but this time I have to use unbound controls to prevent new data entry into a table before the record is ready to be saved.
There is no reason to do editing/entry with unbound controls. I would back up and learn how to use the form's BeforeUpdate event correctly.

Think of the Form's BeforeUpdate event as the flapper at the bottom of a funnel. If the flap is closed, NOTHING gets through. The BeforeUpdate event is the LAST event that runs prior to the saving of a record and it ALWAYS runs if the record is dirty (assuming you put code in it). If a record fails a validation rule, simply cancel the save end exit.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.SomeDate > Date() then
        Msgbox "Date must be <= Today's date.", vbOKOnly
        Cancel = True
        Me.SomeDate.SetFocus
        Exit Sub
    End If
    ...... other code
End Sub
 

Users who are viewing this thread

Top Bottom