Solved

Refresh subform on different tab control

Posted on 2004-08-24
4
978 Views
Last Modified: 2007-12-19
Greetings, Experts...can somebody please help me resolve this? I have a form with 23 tabs, each with a subform linked to its own SQL table. Let's just deal with two for now (subfrm_00_MAIN and subfrm_01_TopDogHouse). Using the following code, I'm trying to refresh the Record_Number of the subform on the second tab, and see it when I click on that tab. This works great if I close the form and reopen, but I get Run-time error '3021': no current record when clicking the 2nd tab. I've tried for a day to resolve this, but can't seem to dial it in. Here's the code:

Private Sub cmdNew_Click()
On Error GoTo Err_cmdNew_Click
    Dim strSQL As String

    DoCmd.GoToRecord , , acNewRec
           
    DoCmd.SetWarnings False
   
       Me.Record_Number.Value = Format(Now(), "mmddhhnnss")
        strSQL = "INSERT INTO dbo_T_01TopDogHouse (Record_Number) VALUES ('" & Me.Record_Number.Value & "');"
        DoCmd.RunSQL strSQL
       
    DoCmd.SetWarnings True
    Me.Record_Date.SetFocus

Exit_cmdNew_Click:
    Exit Sub

Err_cmdNew_Click:
    MsgBox Err.Description
    Resume Exit_cmdNew_Click
   
End Sub
----------------------------------------------
Private Sub TabCtl0_Change()
     
     Select Case Me.TabCtl0.Value
        Case 0
            Me.subfrm_00_MAIN.Form.RecordsetClone.FindFirst "Record_Number =" & Me.Record_Number
            Me.subfrm_00_MAIN.Form.Recordset.Bookmark = Me.subfrm_00_MAIN.Form.RecordsetClone.Bookmark
        Case 1
            Me.subfrm_01_TopDogHouse.Form.RecordsetClone.FindFirst "Record_Number =" & Me.Record_Number
            Me.subfrm_01_TopDogHouse.Form.RecordsetClone.Bookmark = Me.subfrm_01_TopDogHouse.Form.RecordsetClone.Bookmark
     End Select
   
End Sub
0
Comment
Question by:rsanglim
  • 2
4 Comments
 
LVL 3

Expert Comment

by:gemost
ID: 11883340
DId you try putting  the code in the change event in the subforms current event?
When I use subforms on tabs I have found that to get any recordsourse information the code needs to be either in the subform or I use code in the main form such as:

   intAns = Me.subformName.Form.Recordset.RecordCount
   If intAns = 0 Then
     What I want if there is no recordecount
   Else
      What I want if their is a recordcount
   End If

I also used an if statement in the change event instead of  a select case.

      If TabCtlPO = (1 or 2) Then
         What you want to do if the tab you are on equals this number
      End If

hope this helps
gemost :)
0
 

Author Comment

by:rsanglim
ID: 11884204
I tried the subforms current event, without success :(
My current code works great if I close and reopen, but I don't want to have to do that each time when inserting a new record.
0
 
LVL 39

Accepted Solution

by:
stevbe earned 500 total points
ID: 11885312
one way around this without any code is to put a hidden textbox on your main form that holds the current record_number and then use the control as the Master Linking field for all of your subforms, assuming they are all related to the same key. If you have many relationships then you could use m,ultiple hidden textboxes to let Access take care of sync'ng for you.

Steve
0
 

Author Comment

by:rsanglim
ID: 11886674
Steve...EXCELLENT! Simple and quick...don't know why I didn't see that earlier (what a knucklehead!).

...Thanks...Scott
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now