The GPT can comment your code. (1 Viewer)

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:12
Joined
Sep 12, 2006
Messages
15,660
It works because once a query works, it will run a million times, or a billion times. It's the code that follows the error that is vulnerable, especially to inadvertent nulls. If the SQL Statement fails, it will normally not produce records, As I said, thousands of queries, ran millions of times, no errors.
Another reliability enhancer in our systems. No deletions, none ,nada, nowhere. Once a record is in a database, it should never be deleted.
But your code as shown keeps rereading the first record, and must get stuck in a forever loop. Am I missing something?
 

Thales750

Formerly Jsanders
Local time
Today, 05:12
Joined
Dec 20, 2007
Messages
2,146
The AI has show great ability to "think" but only when dealing with technical topics. When dealing with personal topics, it consistently takes a liberal view. Someone programmed that. Just the way that someone programmed Bing to "feature" negative articles on Trump. The evil orange man is living rent free in the heads of the Congress and the media and Bing/MSN is doing its best to make sure I see all the negative articles about Trump even though I never click on them. I can tell by the headlines how biased they will be even if there is some grain of truth to their critique. There is almost never a day where when I open a new window, a Trump article isn't presented front and center. How important is he? Apparently much more important than the real news of the day. Today's lead is "Trump used records requests to get look behind scenes of talks over his taxes" I guess this must be wrong for some reason. It doesn't even seem to be news to me.
I don't use Bing for that exact reason, not Trump per se, I just absolutely do not care about news. Chrome set to open on the Google Search page keeps me sane. I am up on the war, and the economy, the state of technology, other than that, nah.
 

Thales750

Formerly Jsanders
Local time
Today, 05:12
Joined
Dec 20, 2007
Messages
2,146
But your code as shown keeps rereading the first record, and must get stuck in a forever loop. Am I missing something?

Here is the code with some comments. Following the code is an image of output.
Code:
Private Sub cmdImportRaw_Click()

    If IsNull(pubOrdersID) Then
        MsgBox ("Select Order")
        Exit Sub
    End If
    


strSql = "DELETE tblBomImportRaw.RawBomID, tblBomImportRaw.rbOrdersID " & vbCrLf & _
"FROM tblBomImportRaw " & vbCrLf & _
"WHERE (((tblBomImportRaw.rbOrdersID)=getOrdersID()));"
CurrentDb.Execute strSql, dbFailOnError + dbSeeChanges




strSql = "INSERT INTO tblBomImportRaw ( rbID, rbLogDate, rbOrdersID, rbSubCategory, rbFloor, rbManufacturer, rbCode, rbSize, rbDescription, rbCount, rbExtra, rbUnit, rbComment, rbLabel, rbUserID ) " & vbCrLf & _
"SELECT xlsBillOfMaterialsBom.ID, Now() AS Expr2, getOrdersID() AS Expr1, xlsBillOfMaterialsBom.[Sub Category], xlsBillOfMaterialsBom.Floor, xlsBillOfMaterialsBom.Manufacturer, xlsBillOfMaterialsBom.Code, xlsBillOfMaterialsBom.Size, xlsBillOfMaterialsBom.Description, xlsBillOfMaterialsBom.Count, xlsBillOfMaterialsBom.Extra, xlsBillOfMaterialsBom.Unit, xlsBillOfMaterialsBom.Comment, xlsBillOfMaterialsBom.Label, getUserID() AS Expr3 " & vbCrLf & _
"FROM xlsBillOfMaterialsBom;"
CurrentDb.Execute strSql, dbFailOnError + dbSeeChanges


'Add Object Type to all Objects based on  the Heading from the linked Excel File BillOfMaterials.xlsx

Dim strID As String
'Set the start value for the Varible that holds the Heading Value
strID = "0"

    strSql = "SELECT tblBomImportRaw.RawBomID, tblBomImportRaw.rbID, tblBomImportRaw.rbOrdersID, tblBomImportRaw.rbDrawingObjectType " & vbCrLf & _
        "FROM tblBomImportRaw " & vbCrLf & _
        "WHERE (((tblBomImportRaw.rbOrdersID)=getOrdersID())) " & vbCrLf & _
        "ORDER BY tblBomImportRaw.RawBomID;"


'StrID can exist in four states
'1.  as "0"
'2.  as IsNull
'3. As the Current field value from Rs!rbID
'4. As a previous field value from Rs!rbID

'If the value of StrID going into a new record is "0" then it is given the vaule of the current field Rs!rbID
' If it is Null it will skip the first condition and move the the next one which is
' StrID gets the value from the current Rs!rbID
'in both cases Rs!rbDrawingObjecType gets its new value from StrID

 Dim Rs As DAO.Recordset
 
    Set Rs = CurrentDb.OpenRecordset(strSql)
    Rs.Edit
    

    If Rs.RecordCount > 0 Then
        
        Rs.MoveFirst
        Do Until Rs.EOF
        
          
           If IsNull(Rs!rbID) Then
                strID = "0"
            Else
                If strID = "0" Then
                    strID = Rs!rbID
                    Rs.Edit
                    Rs!rbDrawingObjectType = strID
                    Rs.Update
          
                Else
                Rs.Edit
                    Rs!rbDrawingObjectType = strID
                    Rs.Update
                End If
            End If
  
            Rs.MoveNext
        Loop
        Rs.Close
    Set Rs = Nothing
    End If


End Sub

Only the field Rs!rbDrawingObjectType is updated from Function

1675285315061.png
 

Users who are viewing this thread

Top Bottom