Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Learning Functions and Subs 2

Status
Not open for further replies.

AmigoMobility

Technical User
May 8, 2005
57
0
0
US
I'm just starting to built my own functions and subs and would like to ask a
couple of questions, so that I can gain a little more knowledge on how to do
this.

Question #1

If I have a particular Form with a Subform on it and was going to be
referring to it often in my code. How could I make something that would
contain the full name? ie Forms![MainForm]![subForm].Form
Also, once this is done. How would I refer to it, say for instance I was
changing the RecordSource for the subForm.

Question #2
Kind of refers to question #1. How would I built something that would
contain a SQL statement for the RecordSource of the subform and how would I
refer to it.

Hope this makes sense and I appreciate any help you can throw my way.
Shane

 
A couple of quick Ideas,

The first one, maybe declare a Global, Form variable, and
set it at start up,

In a Standard module, you would declare your variable
Global frm As Access.Form

So on your start up form's load event,
Private Sub Form_Load()
Set frm = Forms!frmMain!sfrmChild.Form
End Sub


tio refer from any other class module

Private Sub cmdPayment_Click()
With frm
!txtTax = .07
!txtSubTotal = !txtCost + !txtTax
!txtGrandTotal = !txtSubTotal + !txtGratuity
End With
End Sub


Your other concern,
In Standard Module, create function
Function fSQL() As String
fSQL = "SELECT * FROM tblCountry WHERE txtCity Like 'A*'"
End Function


...just a thought or two.
 
Hey Zion7,

Thanks for your help. I believe you are getting me well started on this project. If I took your example above, then could I go a step further and call it something like this: frm.RecordSource = fSQL

Thanks again,
Shane
 
Hey Zion7,

Thank you very much for the education. I'm off to give it a try. I get back with ya if I screw things up. :) (which I'm quite capable of, unfortuately)

Shane
 
Zion7 and anyone interested,

Here's what I finished up with and it works. Thanks again for helping me through a project that I spent several days trying to accomplish.

Shane

Public Function fCust() As Form

Set fCust = Forms![frmCustomers]![subCusDet].Form

End Function

Function fSQL() As String

fSQL = "SELECT * FROM [Progress Notes] WHERE [Progress Notes].CustomersID =" _
& Forms![frmCustomers]![CustomersID] & " AND [Progress Notes].CreatedBy='" & _
Me.cboEnteredBy.Column(1) & "'"

End Function

And I call it in my code using this:
fCust.RecordSource = fSQL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top