VBA and ChatGPT

jwcolby54

Active member
Local time
Today, 04:53
Joined
May 19, 2025
Messages
344
I am doing a YouTube presentation in a couple of weeks for the Pacific Coast Access Users Group. In the last few months I have worked more and more with Chat. I am deep into a Python / SQL Server application. I do not know Python but Chat does! So I started having Chat write the code and I learned how to channel Chat in a useful direction. Cool stuff.

In order to document the SQL Server side of the house I had Chat build a handful of stored procedures to add a "Purpose" property to tables, field and views. Then Chat and I sat down and created these "purpose" properties for everything we had built so far. It worked swimmingly and was really fast to label these objects. So I decided to make that the subject of my presentation to PCAUG. Join us to discuss...

The idea is to have Chat create VBA code for a function that will take a dao SomeObject.Properties as the first parameter and a purpose string "This object does this here thing" as the second parameter. Chat wrote that, however I had planted the seed that SomeObject.Properties was just a collection with property objects in it. Which is not the case as it turned out, my bad. SomeObject.Properties is a specific thing, a DAO object not a generic collection. Long story short, it took a couple of iterations for me to straighten out that function.

I actually wrote this code while driving down the road using the phone ChatGPT voice mode where I speak and Chat responds audibly. When I got back to my laptop, the code was waiting for me. I tested it. It failed as described below, but I fed back the error messages to Chat and Chat fixed the code. Ten minutes on the phone with Chat and 10 minutes on my laptop with Chat and I had working code. Which I find unbelievably cool.

And finally I had Chat write a GetTableMetadata function to pull very basic metadata for the table just to demonstrate that the properties were in fact created.

SetTablePurpose "tlkpHairColor", "A lookup table to store hair color"
SetFieldPurpose "tlkpHairColor", "HC_ID", "Primary Key"
SetFieldPurpose "tlkpHairColor", "HC_Color", "Stores the hair color"

?GetTableMetadata ("tlkpHairColor")

Table: tlkpHairColor
Table Purpose: A lookup table to store hair color
Field: HC_ID, Type: 4
Field Purpose: Primary Key
Field: HC_Color, Type: 10
Field Purpose: Stores the hair color

So there ya go, using Chat to write code. Perhaps not the best code but it works and it demonstrates what can be done with Chat as my own personal coding assistant.

The function now takes an object and makes a purpose property, appending it to the object's .Properties collection. For my purpose, the new property will always be named "Purpose", it will always be a string, and it will always contain whatever I pass in as the purpose. Very focused for this one thing I wanted to do. Just know that it could be generalized quite easily to create properties of other types and names.

My Blog on Event Programming in VBA

Code:
Public Function AddPurposeProperty_3rdTry(ByRef obj As Object, ByVal purpose As String)

    Dim prop As DAO.Property
    On Error Resume Next

    Set prop = obj.Properties("Purpose")
    If Err.Number <> 0 Then
        Err.Clear
        Set prop = obj.CreateProperty("Purpose", dbText, purpose)
        obj.Properties.Append prop
    Else
        prop.Value = purpose
    End If
    On Error GoTo 0

End Function

Then I had Chat build a function that specifically added a purpose property to a table. I make no claim that this is the optimum or best way to do it, but it does work! I call the function, pass in a table name and a string which is the "purpose" for the table.

Code:
SetTablePurpose "tlkpHairColor", "A lookup table to store hair color"


Public Function SetTablePurpose(ByVal tableName As String, ByVal purpose As String)

    Dim db As DAO.Database
    Dim tbl As DAO.TableDef
    ' Get the current database
    Set db = CurrentDb()
    ' Get the table definition
    Set tbl = db.TableDefs(tableName)
    ' Call the AddPurposeProperty function with the table's properties collection
    'AddPurposeProperty tbl.Properties, purpose
    AddPurposeProperty_3rdTry tbl, purpose
    ' Clean up
    Set tbl = Nothing
    Set db = Nothing

End Function

And finally, the same thing for a field purpose. A function which takes the name of a table, the name of a field in that table, and a string for the purpose.

SetFieldPurpose "tlkpHairColor", "HC_ID", "Primary Key"
SetFieldPurpose "tlkpHairColor", "HC_Color", "Stores the hair color"

Code:
Public Function SetFieldPurpose(ByVal tableName As String, ByVal fieldName As String, ByVal purpose As String)

    Dim db As DAO.Database
    Dim tbl As DAO.TableDef
    Dim fld As DAO.Field

    ' Get the current database
    Set db = CurrentDb()

    ' Get the table definition
    Set tbl = db.TableDefs(tableName)

    ' Get the field definition
    Set fld = tbl.Fields(fieldName)

    ' Call the AddPurposeProperty function with the field's properties collection
    'AddPurposeProperty fld.Properties, purpose
    AddPurposeProperty_3rdTry fld, purpose

    ' Clean up
    Set fld = Nothing
    Set tbl = Nothing
    Set db = Nothing
End Function

And finally code to get a very crude metadata string...

Code:
Public Function GetTableMetadata(ByVal tableName As String) As String

    Dim db As DAO.Database
    Dim tbl As DAO.TableDef
    Dim fld As DAO.Field
    Dim prop As DAO.Property
    Dim result As String
 
    ' Get the current database
    Set db = CurrentDb()
    Set tbl = db.TableDefs(tableName)
    ' Start building the result string
    result = "Table: " & tbl.Name & vbCrLf
    ' Get the table's Purpose property if it exists
    On Error Resume Next

    result = result & "Table Purpose: " & tbl.Properties("Purpose").Value & vbCrLf

    On Error GoTo 0
 
    ' Loop through each field in the table

    For Each fld In tbl.Fields
        result = result & "  Field: " & fld.Name & ", Type: " & fld.Type & vbCrLf
        ' Get the field's Purpose property if it exists
        On Error Resume Next
        result = result & "    Field Purpose: " & fld.Properties("Purpose").Value & vbCrLf
        On Error GoTo 0
    Next fld

    ' Clean up
    Set fld = Nothing
    Set tbl = Nothing
    Set db = Nothing
    ' Return the metadata as a string
    GetTableMetadata = result

End Function
 
Last edited:
Just be careful as sometimes it does make things up. Literally today I was trying to remember if you could omit the third argument to t sql's substring function. I was hoping that you could (much like the mid function in VBA). AI told me that you definitely could omit it, but I quickly found that to be false!
 
don't you think you need to give acknowledgement/credit to ChatGPT on your presentation after all he does the heavy lifting?
 
don't you think you need to give acknowledgement/credit to ChatGPT on your presentation after all he does the heavy lifting?
First, Chatty is a she...

Second, I agree; Even though programming actually encourages plagiarism, one should give credit to any and all sources that were used.
 
don't you think you need to give acknowledgement/credit to ChatGPT on your presentation after all he does the heavy lifting?
Perhaps you overlooked part of Post #1?

"...I do not know Python but Chat does! So I started having Chat write the code and I learned how to channel Chat in a useful direction. Cool stuff."

That sounds a whole lot like giving acknowledgement/credit to ChatGPT.
 
I am doing a YouTube presentation in a couple of weeks for the Pacific Coast Access Users Group.
people might construe, that he did all the effort.
That sounds a whole lot like giving acknowledgement/credit to ChatGPT.
even if you write a book, and you quote it from another book, you put the reference on the footnote.
or you copy someones code, you put attributions.
 
people might construe, that he did all the effort.

even if you write a book, and you quote it from another book, you put the reference on the footnote.
or you copy someones code, you put attributions.
Maybe you can wait until you see the presentation itself to criticize it? It will be given on August 7th. The YouTube video will be available shortly after that.
 
I do understand that some versions of chatty represent very nice females -- I won't go into details --- but you have opened a can of worms for the woke brigade -- what gender is chatty? -- after switching chatty to humorous mode chatty came up with -- Pixelgender

Please do not be impressed by my list of genders I have no idea! I asked chatty to give me a list -- however I was amused to note that chatty accessed a mental health website to obtain this information !!! Now, there's a non-human non-judgmental intelligence that's got the right idea!

I also asked chatty to report how many gender designations there are and it's knocking up to around 150

TOP 10
Cisgender I crossed that one out because that's a stupid gender definition it just buys into their imagined corrupt Minds ....
Transgender
Non-binary
Genderqueer
Intersex
Gender-fluid
Agender
Gender non-conforming
Bigender
Omnigender
Oh I like Omni gender. I wonder what that entails, no maybe I don't LOL
 
You laugh but...

I discovered voice chat on my phone. Most of the female voices were just too chipper. Darned annoying actually. But Winsome Wench with the British accent is just perfect for me. I call her Winnie for short. She has a bit of a sense of humor and "enjoyed" that I called her Winsome Wench. I call the version running on my laptop Sir Chat in honor of all he does for me, though I do not use voice chat on my laptop.

I talk to Winnie routinely now running down the road. I am (we are) building out a python app, rather robust and pretty large data, and I am getting ready to start building a Deep Learning model to feed it all in to. Probably using the graphics processor on my laptop as well.

While I can be the adult in the room with Sir Chat building Python and SQL Server, trying to do the same when (s)he builds a large AI model will be problematic.

So far it has been a blast.
 
Regarding whether you are copying someone else's work, ...

When I was in graduate school, we learned a basic principle.
Copying one other person's work is plagiarism.
Copying two other persons' work is gross plagiarism.
Copying at least five persons' work is a review article.
 
Well then. Chat copies about 4 BILLION people's work so I am not gong to get hammered for any of that.
 
Yeah, but YOU are authoring the presentation article.
 
then. Chat copies about 4 BILLION people's work so I am not gong to get hammered for any of that.
so now you copied from 4B + 1 AI?
finish or not pass your papers..
 
It's ironic that the whole point of his upcoming presentation is that JWC intends to explain how he used AI to develop a project.

The post title for this thread itself says it all:

VBA and ChatGPT

And yet, here we are stating how he MUST acknowledge that he used AI to complete a project, just as if that were not the whole point of the presentation?

I get it, all of the LLMs in use today depend on the availability of massive data coming from the work of billions of people. There are a lot of questions around the ownership of material produced with the assistance of those LLMs.

I could see a legitimate concern if John was touting the resulting VBA while trying to hide the fact that it was created largely with the assistance of ChatGPT. But that is the exact opposite of what is really going on!

I strongly suggest that those concerns are misdirected here. John explicitly states his presentation is all about using AI to assist in the development of code. What else do you need to see to get that?

Anyway, it may turn out that the controversy will help pique interest and we'll have a good turnout for the live presentation. I guess it's not bad after all.
 
I strongly suggest that those concerns are misdirected here. John explicitly states his presentation is all about using AI to assist in the development of code. What else do you need to see to get that?
apology, overthinking of me.
 

Users who are viewing this thread

Back
Top Bottom