Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 23rd, 2003, 11:07 AM
Authorized User
 
Join Date: Dec 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default Field Calculation Upgrade to VBA from Access Basic

I wrote some Access Basic for Access 2 several years ago - it worked fine
but I'm now (finally!) having to upgrade to Access XP. The queries updated
fine, but my Access Basic seems to have to be rewritten. I've been puzzling
for hours over a calculation which worked fine before ..

Formulas used to look like

MyTable!TrstGrwth = Log(MyTable!TrustVal / Val1)

with the exclamation mark between the table and the field reference. This
doesn't produce any error when it is run, but there is no updating of the
table either!

Any leads on how to update this to VBA would be very much appreciated.

Full code as follows ...


Dim MyWorkspace As WorkSpace, MyDatabase As Database, MyTable As Recordset,
Val1 As Single, Val2 As Integer, Val3 As Single
    Set MyWorkspace = DBEngine.Workspaces(0) ' Get default workspace.
    Set MyDatabase = MyWorkspace.Databases(0) ' Get current database.
    Set MyTable = MyDatabase.OpenRecordset("BaseData", DB_OPEN_TABLE) '
Open table.
    MyWorkspace.BeginTrans ' Start of transaction.
    Val2 = 0
    Do Until MyTable.EOF
        Val2 = Val2 + 1
        If Val2 > 1 Then
            MyTable.Edit ' Enable editing.
            MyTable!TrstGrwth = Log(MyTable!TrustVal / Val1)
            MyTable!FTSEGrwth = Log(MyTable!FTSE_100 / Val3)
            MyTable!XSq = MyTable!FTSEGrwth ^ 2
            MyTable!XY = MyTable!FTSEGrwth * MyTable!TrstGrwth
            MyTable!TrackError = MyTable!TrstGrwth - MyTable!FTSEGrwth
            MyTable.Update ' Save changes.
        Else
            MyTable.Edit ' Enable editing.
            MyTable!TrstGrwth = ""
            MyTable!FTSEGrwth = ""
            MyTable!XSq = ""
            MyTable!XY = ""
            MyTable!TrackError = ""
            MyTable.Update ' Save changes.

        End If
        Val1 = MyTable!TrustVal
        Val3 = MyTable!FTSE_100
        MyTable.MoveNext
    Loop
    MyWorkspace.CommitTrans ' Commit changes.
    MyTable.Close ' Close table.
End Function



Thanks

Andrew


 
Old December 23rd, 2003, 12:23 PM
Authorized User
 
Join Date: Dec 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Pavesa
 I wrote some Access Basic for Access 2 several years ago - it worked fine
but I'm now (finally!) having to upgrade to Access XP. The queries updated
fine, but my Access Basic seems to have to be rewritten. I've been puzzling
for hours over a calculation which worked fine before ..

Formulas used to look like

MyTable!TrstGrwth = Log(MyTable!TrustVal / Val1)

with the exclamation mark between the table and the field reference. This
doesn't produce any error when it is run, but there is no updating of the
table either!

Any leads on how to update this to VBA would be very much appreciated.

Full code as follows ...


Dim MyWorkspace As WorkSpace, MyDatabase As Database, MyTable As Recordset,
Val1 As Single, Val2 As Integer, Val3 As Single
    Set MyWorkspace = DBEngine.Workspaces(0) ' Get default workspace.
    Set MyDatabase = MyWorkspace.Databases(0) ' Get current database.
    Set MyTable = MyDatabase.OpenRecordset("BaseData", DB_OPEN_TABLE) '
Open table.
    MyWorkspace.BeginTrans ' Start of transaction.
    Val2 = 0
    Do Until MyTable.EOF
        Val2 = Val2 + 1
        If Val2 > 1 Then
            MyTable.Edit ' Enable editing.
            MyTable!TrstGrwth = Log(MyTable!TrustVal / Val1)
            MyTable!FTSEGrwth = Log(MyTable!FTSE_100 / Val3)
            MyTable!XSq = MyTable!FTSEGrwth ^ 2
            MyTable!XY = MyTable!FTSEGrwth * MyTable!TrstGrwth
            MyTable!TrackError = MyTable!TrstGrwth - MyTable!FTSEGrwth
            MyTable.Update ' Save changes.
        Else
            MyTable.Edit ' Enable editing.
            MyTable!TrstGrwth = ""
            MyTable!FTSEGrwth = ""
            MyTable!XSq = ""
            MyTable!XY = ""
            MyTable!TrackError = ""
            MyTable.Update ' Save changes.

        End If
        Val1 = MyTable!TrustVal
        Val3 = MyTable!FTSE_100
        MyTable.MoveNext
    Loop
    MyWorkspace.CommitTrans ' Commit changes.
    MyTable.Close ' Close table.
End Function



Thanks

Andrew


 
Old December 23rd, 2003, 12:24 PM
Authorized User
 
Join Date: Dec 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I seem to have resolved this - the programming was fine!

Quote:
quote:Originally posted by Pavesa
 I wrote some Access Basic for Access 2 several years ago - it worked fine
but I'm now (finally!) having to upgrade to Access XP. The queries updated
fine, but my Access Basic seems to have to be rewritten. I've been puzzling
for hours over a calculation which worked fine before ..

Formulas used to look like

MyTable!TrstGrwth = Log(MyTable!TrustVal / Val1)

with the exclamation mark between the table and the field reference. This
doesn't produce any error when it is run, but there is no updating of the
table either!

Any leads on how to update this to VBA would be very much appreciated.

Full code as follows ...


Dim MyWorkspace As WorkSpace, MyDatabase As Database, MyTable As Recordset,
Val1 As Single, Val2 As Integer, Val3 As Single
    Set MyWorkspace = DBEngine.Workspaces(0) ' Get default workspace.
    Set MyDatabase = MyWorkspace.Databases(0) ' Get current database.
    Set MyTable = MyDatabase.OpenRecordset("BaseData", DB_OPEN_TABLE) '
Open table.
    MyWorkspace.BeginTrans ' Start of transaction.
    Val2 = 0
    Do Until MyTable.EOF
        Val2 = Val2 + 1
        If Val2 > 1 Then
            MyTable.Edit ' Enable editing.
            MyTable!TrstGrwth = Log(MyTable!TrustVal / Val1)
            MyTable!FTSEGrwth = Log(MyTable!FTSE_100 / Val3)
            MyTable!XSq = MyTable!FTSEGrwth ^ 2
            MyTable!XY = MyTable!FTSEGrwth * MyTable!TrstGrwth
            MyTable!TrackError = MyTable!TrstGrwth - MyTable!FTSEGrwth
            MyTable.Update ' Save changes.
        Else
            MyTable.Edit ' Enable editing.
            MyTable!TrstGrwth = ""
            MyTable!FTSEGrwth = ""
            MyTable!XSq = ""
            MyTable!XY = ""
            MyTable!TrackError = ""
            MyTable.Update ' Save changes.

        End If
        Val1 = MyTable!TrustVal
        Val3 = MyTable!FTSE_100
        MyTable.MoveNext
    Loop
    MyWorkspace.CommitTrans ' Commit changes.
    MyTable.Close ' Close table.
End Function



Thanks

Andrew







Similar Threads
Thread Thread Starter Forum Replies Last Post
Field value matching in Access 2003 VBA procedure rgreeco Access VBA 19 May 24th, 2007 08:37 AM
Calculation in access ashik112 Access 1 February 26th, 2007 08:38 AM
Need Help creating calculation in Access karen.houston Access 2 August 11th, 2006 06:45 AM
Access Workdays calculation doug.hall Access 1 April 26th, 2005 02:19 PM
Access 2000 & 2002 upgrade problem brianharding Access 4 May 3rd, 2004 04:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.