Subform control (1 Viewer)

wallacealeco

Registered User.
Local time
Today, 21:46
Joined
Sep 7, 2011
Messages
23
Hi. Using windows 7, 64 bit and Access 2013 I have a form which contains two sub forms which display related data. My main form has a large button which closes the form. My problem is when I enter data in one of the sub forms (just a date using date picker) I have to click the main form close button twice to make it work. I guess this is because I haven’t pressed enter or moved on from entering the data in the sub form. Is there any way round this? Thanks in anticipation.
 

RuralGuy

AWF VIP
Local time
Today, 14:46
Joined
Jul 2, 2005
Messages
13,826
What have you tried so far? What code do you have in the Large Close Button on the Main Form?
 

jdraw

Super Moderator
Staff member
Local time
Today, 16:46
Joined
Jan 23, 2006
Messages
15,378
Further to Allan's comments, can you step back and tell us about the business that is supported by this form, subform and the underlying database?
Remember, we only know what you tell us. We know nothing of the application, tables and relationships, nor the purpose of the form. It's difficult to answer a question without some context.
Good luck.
 

Wayne

Crazy Canuck
Local time
Today, 16:46
Joined
Nov 4, 2012
Messages
176
Here's the code I use, and it is on the main form that has 4 subforms, and it works without having to click twice.

Code:
Private Sub btnCloseForm_Click()

    On Error GoTo Err_btnCloseForm_Click

    DoCmd.Close acForm, "YourFormNameHere", acSaveYes
    
Exit_btnCloseForm_Click:
    Exit Sub

Err_btnCloseForm_Click:
    MsgBox Err.Description, vbInformation, "Attention"
    Resume Exit_btnCloseForm_Click
    
End Sub

That goes in the On Click event of the Close Button. It has worked perfectly for me. Hope that helps.
 

wallacealeco

Registered User.
Local time
Today, 21:46
Joined
Sep 7, 2011
Messages
23
Thank you for your replies and apologies for my delay getting back.
Ruralguy, the code on the Close button is a pretty standard DoCmd. Close. This works as expected.
Jdraw, the database is home use home use only and is basically a list of numbers our band play. Other related tables/forms are a list of dates when numbers were rehearsed and a
list of when numbers were played at a concert.
From a main, continuous Form double clicking on a song title brings up a Form with extra data on each number. This new form also has two sub forms showing the rehearsal/ concert dates.
When I enter a date on a sub form using date picker, unless I press enter or move to another field, when I click the close button on the main form I have to click twice. First time seems to put focus back to the main form, second click closes the form. I have tried using On Change event of the sub form field to set focus to main form close button and although this moves the focus I still have to click twice. Th@nks in anticipation.
 

isladogs

MVP / VIP
Local time
Today, 21:46
Joined
Jan 14, 2017
Messages
18,215
Check whether you have a form current event that is being triggered first.
 

Users who are viewing this thread

Top Bottom