473,508 Members | 4,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sytax help for refering to control on subform

Hi All,

Love this site, have gotten a lot from it. This is my first time
posting though, so forgive me for any errors.

I have an Access 2000 db where I have a main form of Contractors and on
the main form is a subform of bonds carried by those contractors. I am
trying to reference a field named "Bond" located on the subform in
code that is run from the mainform and am having trouble with the
syntax for this. Below is a sample of just some of the code that I
have tried.

If Me.FraSearch.Value = "1" Then
strField =
"[Forms]![frmCustomerBonds]![frmBondsSubform]![BondNum] = '" &
Me![txtLookup] & "'"
ElseIf Me.FraSearch.Value = "2" Then
strField = "[LiscNum] = '" & Me![txtLookup] & "'"
Else
strField = "[LastName] = '" & Me![txtLookup] & "'"
End If

By the way the strField references in the 2nd and 3rd then statement
of the above code work, it is the first Then statement I am having
trouble with. Would be glad for any assistance as I am loosing hair by
the handful on this one.

Nov 13 '05 #1
3 1825
It may help if I mention that strField is used as the criteria of
FindFirst, code as follows
rs.FindFirst strField

Thanks again in advance

Nov 13 '05 #2
The syntax for referencing a Control in a Form embedded in a Subform Control
from VBA code attached to the main form is:

Me!SubformControlName.Form!ControlNameinSubform

That does not appear to be what you are using. Note that you do not refer to
the Form in the Subform Control, but to the Form _property_ of the Subform
Control.

That will access whichever is the currently-selected Record in the Form
embedded in the Subform Control. That may not be the one you want and also
may not be obvious if it is in continuous-form view with multiple records
displayed. Thus, if you need to access something other than the
currently-selected Record, or if the user might possibly click and select a
different Record, then you may want to rethink your approach to the problem.

Larry Linson
Microsoft Access MVP

"Kranman" <st***@calaoms.org> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi All,

Love this site, have gotten a lot from it. This is my first time
posting though, so forgive me for any errors.

I have an Access 2000 db where I have a main form of Contractors and on
the main form is a subform of bonds carried by those contractors. I am
trying to reference a field named "Bond" located on the subform in
code that is run from the mainform and am having trouble with the
syntax for this. Below is a sample of just some of the code that I
have tried.

If Me.FraSearch.Value = "1" Then
strField =
"[Forms]![frmCustomerBonds]![frmBondsSubform]![BondNum] = '" &
Me![txtLookup] & "'"
ElseIf Me.FraSearch.Value = "2" Then
strField = "[LiscNum] = '" & Me![txtLookup] & "'"
Else
strField = "[LastName] = '" & Me![txtLookup] & "'"
End If

By the way the strField references in the 2nd and 3rd then statement
of the above code work, it is the first Then statement I am having
trouble with. Would be glad for any assistance as I am loosing hair by
the handful on this one.

Nov 13 '05 #3
Larry,

Thanks for the reply it helps a little. As I mentioned above I had
tried several different ways to structure the syntax for this. I
believe that I even tried what you have provided (which I had found
while searching different strings prior to posting). After setting the
syntax back to your example, I still receive an error when running the
code that states " The Microsoft Jet database engine does not
recognize 'Me!SubBonds.Form!BondNum' as a valid field name or
expression". So I set up a button on the form to check the syntax by
setting the BondNum control's visible property to False on the
subform. As I suspected the button works, so the syntax is correct.
So what I thought was a syntax error, is now a problem with my code. So
I am providing the entire procedure below in the hope that my error is
spotted.

What I would like is for the user to click in a search box , after
select the License check box to find a contractor by license number,
then clear out the search box input a bond number and find a bond on
the sub form related to the contractor( as some contractors have
numerous bonds). Once again the procedure works for fields that are
located on the main form. The problem arises when searching for a
record on the subform.

Private Sub btnFind_Click()

' Find the record that matches the control.
Dim rs As Object
Dim strField As String
' Determine Field to Search By
If Me.FraSearch.Value = "1" Then
strField = "Me!subBonds.Form![BondNum] = '" & Me![txtLookup] &
"'"
Set rs = Me!subBonds.Form.Recordset.Clone
ElseIf Me.FraSearch.Value = "2" Then
strField = "[LiscNum] = '" & Me![txtLookup] & "'"
Set rs = Me.Recordset.Clone
Else
strField = "[LastName] = '" & Me![txtLookup] & "'"
Set rs = Me.Recordset.Clone
End If

' Search Customer Bond Form for select value
If IsNull(Me.txtLookup.Value) Then
MsgBox "You have not entered a value to search by",
vbExclamation, "CBS Search Error"
Me.txtLookup.SetFocus
Exit Sub
Else
rs.FindFirst strField
If rs.NoMatch Then
MsgBox "No Record Found for " & Me.txtLookup,
vbExclamation, "CBS Serch Error"
Else
Me.Bookmark = rs.Bookmark
End If
End If

End Sub

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3284
by: David B | last post by:
I have a sub form in datasheet view on a form. I want a query to find the recordid every time a different row on the datasheet has the focus. The query is grabbing data for a combo on a second sub...
8
3331
by: deko | last post by:
I'm hoping someone can sanity check my understanding of the Object Model for Forms/Controls. I'm having trouble drilling down into Control properties. First, I have a record set with the...
12
18978
by: MLH | last post by:
I have created two forms: frmBrowseNegsMainform and frmBrowseNegsSubform. I put a subform control on the first of these. The SourceObject property for the subform control is, of course,...
3
4160
by: Not Me | last post by:
Hi, Just trying to get my head around tab controls, is there anywhere which would describe the structure of how they work? I seem to be ok so far, being able to check which page I'm on etc......
4
1331
by: Terri | last post by:
Main form-frmCheckRequest Sub form-subfrmCheckRequestPayments On my subform I have 2 fields FundCode and ClassNumber. Both are comboboxes. I'm trying to filter ClassNumber based on FundCode. ...
4
1713
by: rhc | last post by:
access 2000 I have a tab control with 2 pages and one subform on each. On parent form P from the form_current() event of subform A I cant seem to refer to subform B. msgbox forms!.form.name...
7
12280
by: ApexData | last post by:
I am using the following code in my TabControl to manage subform loads. The code assigns the subForms SourceObject. - Do I also need code to DeAssign the SourceObject when leaving the Tab, I'm...
5
3620
by: CanOfWorms | last post by:
Access 2003 (previous 2000) Windows XP Pro I am fairly new at VBA within Access, learning as I go thorugh forums and discussion groups. I generally find my answers through previous posts, but I...
1
3230
by: veteranwebdesign | last post by:
Hello, I have a main form. I want forms to open in a subform control box. What is the code for the option group to open the subforms in the control box. I didn't create subforms, I created...
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.