Two forms with same record source prevent writing conflict (1 Viewer)

bruceblack

Registered User.
Local time
Today, 11:37
Joined
Jun 30, 2017
Messages
119
Dear friends,

I'll keep it short and sweet.

I have two forms, with the same record source. Say form A and form B.

Form-A is the main form. But Form-B goes into more detail.
Both forms are showing completely different fields on it. But once i entered the details in Form-B, close it, and want to close Form-A, i get a writing conflict.

So, i kind of understand why i think? And i don't have any record locks enabled. But since i am not changing the same fields, i am confused on how to solve the issue. I tried just saving the records (vba) before i open or close them, but then i get the error that i can not save the record right now.

Is there simple fix? I just want to edit some details in another form with the same record source if possible. Thanks in advance!


1683371977135.png
 

isladogs

MVP / VIP
Local time
Today, 11:37
Joined
Jan 14, 2017
Messages
18,225
Close Form A before editing in Form B ...or just use one form hiding the additional detail when not needed
 

bruceblack

Registered User.
Local time
Today, 11:37
Joined
Jun 30, 2017
Messages
119
Close Form A before editing in Form B ...or just use one form hiding the additional detail when not needed
Who else than isladogs :)

Thank you. I did that actually. The problem was that Form-A is a continuous form. So when i am scrolling, and i close it, i have to scroll back to where i left off each time. Which gets annoying fast.

I understand that its just not possible other than that? I think i used it like that in the past somehow. But i could be wrong.

The second option is just too much. I would have alot of empty space on my form. The details forms is quite elaborate.
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:37
Joined
Sep 21, 2011
Messages
14,301
Try removing the record source.?
Easy enough to store the id, to go back to the record you were on.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 06:37
Joined
May 21, 2018
Messages
8,529
The most common way to do this properly is
1 )Form A stores the ID of the current record in a variable
2) form A calls pop up form FormB using the DOCMD.Openform
using the WHERE argument of the Docmd to open the correct record
using the ACDIALOG value of the Docmd.open form WINDOWMODE argument. This stops code execution in FormA until FormB is closed
4)Once form B closes execution returns in Form A
5) Form A requeries
6) Form A moves back to the record whose ID is stored in step 1

Code:
Private SomeEventProcedure()
  dim id as long
  ID = Me.somePrimaryKeyField
  docmd.OpenForm FormName := "FrmName", WhereCondition: = "SomePKfield:= " & ID, WindowMode:= ACDIALOG
  'code stops in FormA until FormB closes
 'Resumes here
  me.requery
  me.recordset.findfirst "SomePrimaryKeyField = " & ID
end sub

You must use ACDIALOG if not code execution in Form A continues and the requery happens immediately before anything happens in FormB.
 

isladogs

MVP / VIP
Local time
Today, 11:37
Joined
Jan 14, 2017
Messages
18,225
The second option is just too much. I would have a lot of empty space on my form. The details forms is quite elaborate.
You can easily shrink / expand the form as required. For example, see
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:37
Joined
Feb 19, 2013
Messages
16,612
The problem was that Form-A is a continuous form.
have you considered creating something like the split form ? I don't recommend the built split form but 'grow your own' is OK. Simplistically have a continuous form and in the header or footer repeat the controls and layout in a 'single form' style.

Or if Form A is effectively just a list, use a listbox?

Or set the Form A recordset type to snapshot? (haven't tested). But if it works if there are fields that could be modified by Form B you would need to refresh the recordset (no need to requery unless Form B adds or deletes records)








 

Gasman

Enthusiastic Amateur
Local time
Today, 11:37
Joined
Sep 21, 2011
Messages
14,301
@MarkK produced a few lines of code for what I call an ESF form (Emulated Split Form)
@isladogs enhanced the idea. Search for ESF and my user name if that might be of interest for you.
 

isladogs

MVP / VIP
Local time
Today, 11:37
Joined
Jan 14, 2017
Messages
18,225

 

Users who are viewing this thread

Top Bottom