Solved need to add a new record via button based on filter from main form (1 Viewer)

jprat

New member
Local time
Today, 06:52
Joined
Apr 6, 2021
Messages
4
Hi,

I'm new to vba/macros in access. I have a main form that is built from scratch with fields from different tables and I have a search filter on it. When the search filter populates an employee, I want to be able to add a new record (case ID) for that employee. I've tried different codes for the add record button, but it either doesn't work or it just adds a new record to the form entirely and "clears out" the employee that is filtered (see screenshot below). There are also 3 other subforms on the mainform that need to have the new id to populate. I am able to get the save button, other navigation buttons to work on the main form as it should. I just don't know how to do the add record for a specific employee that is being searched. How can I do this?

1617695293500.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:52
Joined
May 7, 2009
Messages
19,169
the Normal is that you Type it in the subform.
you first fill your main form with the New record info.
then you go to the subform and fill them.

if all your subform has Link Master/Child fields (caseID), then you do not need
to enter the caseID, only the other fields.
 

jprat

New member
Local time
Today, 06:52
Joined
Apr 6, 2021
Messages
4
the Normal is that you Type it in the subform.
you first fill your main form with the New record info.
then you go to the subform and fill them.

if all your subform has Link Master/Child fields (caseID), then you do not need
to enter the caseID, only the other fields.
hi thank you for the reply! So, I do have the child/master linked by CaseID and EmployeeID. However, if I go your route-- I found that I would need to turn another table into a subform so that I can have a add button on that subform which allows me to create a new case, but I'd have to close out of the main form entirely and reopen to see the new case added into the other subforms. I've attached my sample DB. If you open the form titled MainForm, you can see what I am referencing to.
 

Attachments

  • sampletest (2).accdb
    740 KB · Views: 338

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:52
Joined
May 7, 2009
Messages
19,169
i added an Unbound textbox on Main form (txtUnbound, see in design view of form).
i used this as Master Link Fields.
 

jprat

New member
Local time
Today, 06:52
Joined
Apr 6, 2021
Messages
4
i added an Unbound textbox on Main form (txtUnbound, see in design view of form).
i used this as Master Link Fields.
Hi, thank you for adding that. Just to confirm, for the master/child fields-- instead of using what is available in the ellipses, I can actually chose to manually type in the field name as long as the data type is the same? i.e. field 1 data type is number and field 2 data type is number.

Also, there is this message that keeps populating. It's happens when I open the form initially, click add record button, then start working on the dates. I'm not understanding why it is doing it because I don't have see anything related to the bullets. I doubt the field value is the issue because it's an autogenerated case ID. Could you please explain?

1617703380928.png
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:52
Joined
May 7, 2009
Messages
19,169
i remove the txtUnbound, and instead make Case ID (on Main form) as Unbound and renamed it as txtUnbound.
note that this textbox is read-only.
i also added code to the Subform's Error Event to handle our unwanted error.
 

jprat

New member
Local time
Today, 06:52
Joined
Apr 6, 2021
Messages
4
oh, I see so that unbound textbox was causing the error! I see your code, but for my knowledge is there a good resource to reference on handling errors like this? I'm learning VBA and I've found random sites that provide bits of information. I just need something that would be more detailed. Anything is appreciated!
 

Users who are viewing this thread

Top Bottom