Results 1 to 4 of 4
  1. #1
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149

    call sub after setting form's record source

    I first get a new Bill No. & BillId, I set the gblKeyId=BillId, then I call the frmBill as below.
    It runs Form_Open then wait for me to enter data.
    when I click the Save button btnSave_Click, it runs to get a next Bill No., append new bill record, then go back to Form_Open.
    But when it runs the Me.RecordSource, it steps to IssueDate_LostFocus, then back to the rest after Me.RecordSource.
    But when form first display, it does not step to IssueDate_LostFocus.


    The textbox IssueDate has Tab Index=0 and Tab Stop=Yes.

    Code:
    Private Sub Form_Open(Cancel As Integer)
        Me.RecordSource = "SELECT * FROM bill WHERE billId=" & gblKeyId
        ...
    End Sub
    Private Sub IssueDate_LostFocus()
        Me.ExchRate = GetExchangeRate(Me.IssueDate, Me.CurCode)
    End Sub
    Private Sub btnSave_Click()
        Dim DocNo As String
        DocNo = NewDocumentNo("Bill")
        DoCmd.RunCommand acCmdRecordsGoToNew
        Me.BillNo = DocNo
        Me.Refresh
        gblKeyId = Me.BillId
        Form_Open (0)
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,945
    Why do you need to open an open form?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149
    just to run the codes in Form_Open to initialize the controls (textbox,combobox) to capture next bill information.

  4. #4
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    But when form first display, it does not step to IssueDate_LostFocus.
    The textbox IssueDate has Tab Index=0 and Tab Stop=Yes.
    Lost focus fires when you leave a control
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Problem on setting source in continuos form
    By diegomarino in forum Access
    Replies: 7
    Last Post: 05-10-2020, 06:32 PM
  2. Setting a Textbox Record Source
    By carterlangley in forum Access
    Replies: 2
    Last Post: 02-28-2018, 11:53 AM
  3. Setting Control Source Property Issue
    By Sarah11 in forum Forms
    Replies: 2
    Last Post: 09-23-2017, 10:37 PM
  4. Replies: 3
    Last Post: 02-08-2016, 02:22 PM
  5. Form with Subreport and setting record source.
    By Monterey_Manzer in forum Forms
    Replies: 3
    Last Post: 02-14-2013, 05:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums