Advertisement

06.05.2008 at 03:03PM PDT, ID: 23462081
[x]
Attachment Details

How do I call a Function from a Sub Procedure

Asked by rpreiss in Access Coding/Macros, Access Forms, VB Script

Tags: microsof, Access VBA

I have the following code and want to run it from the sub:

Private Sub Form_Load()

I am new to VBA and appreciate any help.  Thanks.

ArtieStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
Function fnGetFieldsOfTable(sTable As String) As Boolean
    
    'fn to create table holding field names of input table parameter
    Dim d As DAO.Database, f As Field, t As TableDef, sql As String
    Dim r As DAO.Recordset
    Dim sTemp As String
    
    sTemp = "tmpTableFieldList"
    Set d = CurrentDb
    Set t = d.TableDefs(sTable)
    On Error Resume Next
    DoCmd.DeleteObject acTable, sTemp
    
    On Error GoTo errH
    'create table
    sql = "select '1' as TableName, '1' as FieldName into " & sTemp & " from " & sTable & " where 1 = 0"
    Debug.Print sql
    d.Execute sql
    Set r = d.OpenRecordset(sTemp)
    For Each f In t.Fields
            r.AddNew
                r!tablename = sTable
                r!FieldName = f.Name
            r.Update
    Next
    Set r = Nothing
    Set f = Nothing
    Set d = Nothing
    Exit Function
    
errH:
    Beep
    MsgBox Err & " " & Err.Description
    Set d = Nothing
End Function
[+][-]06.05.2008 at 03:06PM PDT, ID: 21724484

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Access Coding/Macros, Access Forms, VB Script
Tags: microsof, Access VBA
Sign Up Now!
Solution Provided By: YourReference
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.05.2008 at 03:06PM PDT, ID: 21724486

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628