VBA code for Command buttons on child form (1 Viewer)

access account

Registered User.
Local time
Today, 07:46
Joined
Jun 4, 2012
Messages
14
record buttons do not work on child frm when frm accessed through parent frm

Hi! I am very new to Access 2003 and I've run into a problem with the command buttons on one of my forms. I have a main form that has a command button that opens up a second form, on the second form my Record Navigation 'go to previous record' and Record Navigation 'go to next record' buttons do not work, I receive the error: You can't go to the specified record. However, when I open this second form up by itself these buttons function as they should. @AccessMSSQL mentioned that when I open the second form through the command button, this may cause only one record to be displayed so I can't move to next or previous. If this is the case, is they a way I can get the Record Navigation buttons to work as they should if I open the second form through the command button on the main form? The code I have for the previous Record Navigation button on the second form is: Private Sub Previous_Disease_Condition_Button_Click() On Error GoTo Err_Previous_Disease_Condition_Button_Click DoCmd.GoToRecord , , acPrevious Exit_Previous_Disease_Condition_Button_C: Exit Sub Err_Previous_Disease_Condition_Button_Click: MsgBox Err.Description Resume Exit_Previous_Disease_Condition_Button_C End Sub
 
Last edited:

AccessMSSQL

Seasoned Programmer-ette
Local time
Today, 06:46
Joined
May 3, 2012
Messages
636
It sounds like you are opening the 2nd form using a filter (where clause). It will cause the 2nd form to open with only one record displayed so you can't move to next or previous. In your move to previous, move to next buttons before the code performs you could try this code:

DoCmd.RunCommand acCmdRemoveFilterSort

You may have problems with this in that it will return you to the first record in the form.


http://www.accessmssql.com/
 

access account

Registered User.
Local time
Today, 07:46
Joined
Jun 4, 2012
Messages
14
Thank you for the response, I tried your suggestion and unfortunately I am still having the same problem.
 
Last edited:

AccessMSSQL

Seasoned Programmer-ette
Local time
Today, 06:46
Joined
May 3, 2012
Messages
636
hmmm...do you have recordselectors and navigation set on the 2nd form. When you open it can you see the record count at the bottom? How many records are there?
What is the code behind the button on your main form?


http://www.accessmssql.com/
 

Simon_MT

Registered User.
Local time
Today, 14:46
Joined
Feb 26, 2007
Messages
2,177
Basically, you have to open your second form the same as the first.

Here is an example of wanting to go from Client Details to Interest and Sales:
Code:
Function ClientsInterestClient() As String

    With CodeContextObject
        DoCmd.OpenForm "Clients Interest Enquiry", acNormal, "", ClientsFilter, acReadOnly, acWindowNormal
        DoCmd.GoToRecord acDataForm, "Clients Interest Enquiry", acGoTo, .CurrentRecord
        DoCmd.Close acForm, "Clients Details"
    End With
End Function
You should have the same number of record for both Forms and a sorting regime that is exactly the same.

Simon
 

Users who are viewing this thread

Top Bottom