C
Chris Burnette
Ok, I have a main form with a tab control on it, and on each page of the tab
control is a subform. These subforms are not linked to the main form using
LinkMaster/LinkChild fields, primarily because they are not one-to-many
relationships, but also because I want to be able to use the Find function on
these forms.
So, I have been writing my own code in VBA to link up the forms. I have
already set the relationships between the tables in the Relationships window
in Access, so everything should have the correct FK relationship.
I have two procedures that I have been writing. My first procedure is
intended to set the current record in the subform (the one in the active page
of the tab control) to match the current record in the main form. Although I
don't get any errors when I run this code, it just doesn't seem to work.
Sub LinkRecords()
'This procedure needs to go to the record that is current in the TabForm
Dim MyVar As Variant
Dim MyForm As String
'MyForm needs to be set to the form in the active page of the tab control.
If CurrentProject.AllForms("AuthorSubform").IsLoaded = True Then
MyForm = Forms!TabForm!ctlAuthorSubform.SourceObject
Forms!TabForm!BookID.SetFocus
MyVar = Forms!TabForm!BookID.Text
DoCmd.GoToRecord acDataForm, MyForm, acGoTo, MyVar
Forms!TabForm.SetFocus
End If
End Sub
My second procedure is intended to create a new record in the subform when a
new record is created in the main form, and set the value of the FK in the
subform equal to the value of the PK in the main form. When I try to run
this code, I get the error "there is an invalid method in an expression", and
it takes me to this line:
Forms!TabForm!ctlAuthorSubform.Form.SetFocus
It seems that it doesn't like my syntax, as technically Form is a property,
although (I think) it refers to the form that is designated by SourceObject
property of my subform control.
My code is below:
Sub NewRecordMark()
'This is the procedure that takes place to link up new records when they are
created.
Dim intnewrec As Integer
intnewrec = Me.NewRecord
If intnewrec = True Then
Forms!TabForm!ctlAuthorSubform.Form.SetFocus
DoCmd.GoToRecord acDataForm, "AuthorSubform", acNewRec
Forms!TabForm!AuthorSubform.Form!BookID.SetFocus
If Forms!TabForm!AuthorSubform.Form!BookID.Text = 0 Then
Forms!TabForm!AuthorSubform.Form!BookID =
Forms!TabForm!BookID.Text
End If
End If
End Sub
I know there must be another way to do this, however I'm not really sure
what it is, so if someone can help me get my code right I would greatly
appreciate it.
Thanks,
Chris
control is a subform. These subforms are not linked to the main form using
LinkMaster/LinkChild fields, primarily because they are not one-to-many
relationships, but also because I want to be able to use the Find function on
these forms.
So, I have been writing my own code in VBA to link up the forms. I have
already set the relationships between the tables in the Relationships window
in Access, so everything should have the correct FK relationship.
I have two procedures that I have been writing. My first procedure is
intended to set the current record in the subform (the one in the active page
of the tab control) to match the current record in the main form. Although I
don't get any errors when I run this code, it just doesn't seem to work.
Sub LinkRecords()
'This procedure needs to go to the record that is current in the TabForm
Dim MyVar As Variant
Dim MyForm As String
'MyForm needs to be set to the form in the active page of the tab control.
If CurrentProject.AllForms("AuthorSubform").IsLoaded = True Then
MyForm = Forms!TabForm!ctlAuthorSubform.SourceObject
Forms!TabForm!BookID.SetFocus
MyVar = Forms!TabForm!BookID.Text
DoCmd.GoToRecord acDataForm, MyForm, acGoTo, MyVar
Forms!TabForm.SetFocus
End If
End Sub
My second procedure is intended to create a new record in the subform when a
new record is created in the main form, and set the value of the FK in the
subform equal to the value of the PK in the main form. When I try to run
this code, I get the error "there is an invalid method in an expression", and
it takes me to this line:
Forms!TabForm!ctlAuthorSubform.Form.SetFocus
It seems that it doesn't like my syntax, as technically Form is a property,
although (I think) it refers to the form that is designated by SourceObject
property of my subform control.
My code is below:
Sub NewRecordMark()
'This is the procedure that takes place to link up new records when they are
created.
Dim intnewrec As Integer
intnewrec = Me.NewRecord
If intnewrec = True Then
Forms!TabForm!ctlAuthorSubform.Form.SetFocus
DoCmd.GoToRecord acDataForm, "AuthorSubform", acNewRec
Forms!TabForm!AuthorSubform.Form!BookID.SetFocus
If Forms!TabForm!AuthorSubform.Form!BookID.Text = 0 Then
Forms!TabForm!AuthorSubform.Form!BookID =
Forms!TabForm!BookID.Text
End If
End If
End Sub
I know there must be another way to do this, however I'm not really sure
what it is, so if someone can help me get my code right I would greatly
appreciate it.
Thanks,
Chris