Solved Trouble adapting Uncle Gizmos Checklist code.

HillTJ

To train a dog, first know more than the dog..
Local time
Yesterday, 20:34
Joined
Apr 1, 2019
Messages
730
Hi, I've done the tutorial kindly & thoroughly covered by Uncle Gizmo on his website dealing with the set up of checklists. I'm a bit 'green'with VBA so I don't understand a lot!. I'm hoping that someone familiar with this code can help. I do not wish to post the full code as I think it is Uncle Gizmos intention for me to learn the code myself rather than simply copy & paste exercise. I respect that.
I have 2 problems;
1) I've copied this to a standard module;

Code:
Option Compare Database
Option Explicit
Private Function fcopyListToData(lngMasterID As Long)
On Error GoTo Error_Handler
    Dim strSubName As String
    Dim strModuleName As String
    Dim curDB As DAO.Database
    Dim rsList As DAO.Recordset
    strSubName = "FcopyListToData"
    strModuleName = "Form - " & Me.Name

    Set curDB = CurrentDb

    Dim lngSet As Long
    Dim lngID As Long

            Set rsList = curDB.OpenRecordset(fSQL_List, dbOpenForwardOnly)
        
                Do Until rsList.EOF
                    lngSet = rsList!listSets
                    lngID = rsList!ListID
                
                    Call fAppendListToData(lngMasterID, lngSet, lngID)
                
                    rsList.MoveNext
                Loop
Exit_ErrorHandler:

    Exit Function

Error_Handler:
'
Resume Exit_ErrorHandler

End Function
I get a compile error at me.Name!! Why?

2) I dont't understand strSQL3 of the following module;

Code:
Private Function fSQL_Data(lngMasterID As Long) As String
On Error GoTo Error_Handler

    Dim strSQL0 As String
    Dim strSQL1 As String
    Dim strSQL2 As String
    Dim strSQL3 As String
    Dim strSQL4 As String
       
  strSQL1 = "SELECT datalinkID,datasets,dataItems,DataTickedOff "
  strSQL2 = "FROM tblData "
  strSQL3 = "Where (((datalinkID)=1" ' this is used for 1 only....I think this is an error.

  strSQL4 = "));"
 
  strSQL0 = strSQL1 & strSQL2 & strSQL3 & strSQL4
 
  fSQL_Data = strSQL0
  'Debug.Print fSQL_Data
Exit_ErrorHandler:
   
    Exit Function
   
Error_Handler:
'
Resume Exit_ErrorHandler
 
End Function
Surely, this should be a variable? I put a 1 in it to test but I think should be a variable.
3) in the tutorial the "code" to fill the subforms was called from the "Current" event but in a later tutorial the code was called from the "on Load" event. What do I do?
 
Last edited by a moderator:
I'm not familiar with his sample, but Uncle is probably asleep. You can't use "Me" in a standard module. It is used as a shortcut to refer to the object containing the code, ie a form or report. It appears the code is supposed to be in a form's module.

Given the context, I expect the code for strSQL3 is supposed to use the ID that is passed to the function. Like:

strSQL3 = "Where (((datalinkID)=" & lngMasterID

As to the events, the load event will only run when the form first opens, the current event will fire at that time plus any time the displayed record changes. Use whichever is appropriate to your situation.
 
pbaldy, thanks for the prompt response. I'll give both of those recommendations a go. I thought it was something like that.
 
No problem, post back if you get stuck. Hopefully I've made good assumptions.
 
pbaldy, You're suggestion seemed to work. Thanks. Got another problem though, See code that is on "On Load" event of main form. It is supposed to point the record source of each of my 5 subforms at a different data set.

Code:
Private Sub Form_Load()
'LocationID  Location
'1   Inspection 1
'2   Inspection 2
'3   Inspection 3
'4   Inspection 4
'5   Inspection 5

Me.subFrm1.Form.RecordSource = "SELECT tblData.DataID, tblData.DataLinkID, tblData.dataSets, tblData.dataItems, tblData.DataTickedoff FROM tblData WHERE (((tblData.dataSets)=1));"
Me.Label1.Caption = "Inspection 1"
Me.subFrm2.Form.RecordSource = "SELECT tblData.DataID, tblData.DataLinkID, tblData.dataSets, tblData.dataItems, tblData.DataTickedoff FROM tblData WHERE (((tblData.dataSets)=2));"
Me.Label2.Caption = "Inspection 2"
Me.subFrm3.Form.RecordSource = "SELECT tblData.DataID, tblData.DataLinkID, tblData.dataSets, tblData.dataItems, tblData.DataTickedoff FROM tblData WHERE (((tblData.dataSets)=3));"
Me.Label3.Caption = "Inspection 3"
Me.subFrm4.Form.RecordSource = "SELECT tblData.DataID, tblData.DataLinkID, tblData.dataSets, tblData.dataItems, tblData.DataTickedoff FROM tblData WHERE (((tblData.dataSets)=4));"
Me.Label7.Caption = "Inspection 4"
Me.subFrm5.Form.RecordSource = "SELECT tblData.DataID, tblData.DataLinkID, tblData.dataSets, tblData.dataItems, tblData.DataTickedoff FROM tblData WHERE (((tblData.dataSets)=5));"
Me.Label5.Caption = "Inspection 5"
End Sub

It does not populate subFrm2 onwards with datasets = 2 etc. I pretty much copied this from the Uncle Gizmo tutorials. If I substitute 1 for 2 it populates subform 2 with data from dataset =1 OK. Each subform says 1 of 5 (which is correct) but i think the records are not being displayed

Any Ideas?
 
Last edited by a moderator:
not sure if this is a typo but it your trying to concatenate a form module name like Form_Form1 this is wrong

strModuleName = "Form - " & Me.Name

should be an underscore not a dash
strModuleName = "Form_ " & Me.Name
 
As good as!

It's my birthday,and I've been celebrating!

I'm just off to bed!

Not according to AWF.

bday.JPG


Happy Birthday U.G.! 🍰
 
It does not populate subFrm2 onwards with datasets = 2 etc. I pretty much copied this from the Uncle Gizmo tutorials. If I substitute 1 for 2 it populates subform 2 with data from dataset =1 OK. Each subform says 1 of 5 (which is correct) but i think the records are not being displayed

I don't see where this has been addressed, but I just got off the road from a 7 hour drive. Offhand the code looks appropriate. Can you attach the db here to play with?
 
pbaldy, please see attached. I appreciate your perseverance. Also in the 'copy list to data' it seems to copy the most recent entry twice? Have a look at tblData.
 

Attachments

pbaldy, please see attached. I appreciate your perseverance. Also in the 'copy list to data' it seems to copy the most recent entry twice? Have a look at tblData.

I'm going to let Uncle address his code, as I haven't really tried to follow what the intent is. To your problem with the subforms, I think it has to do with the combo. I don't like datasheet view, can't figure out why all the fields aren't showing, don't have time to follow up (just got home from long drive, dinner in a few). If I change to continuous view, it looks like the appropriate records are in each subform. Something in your combo is not displaying the values in it:

1592271385972.png
 
pbaldy, cheers. Thanks for following up this matter.
 
Somebody bought me a bottle of Southern Comfort, I now have a half-empty bottle of Southern Comfort!
Sounds like you don't like SC too much if you have half of it left. 🥴

I'd rather have half a bottle of JD left.
 
Uncle Gizmo, thanks. So this code will replace the code shown in post 18?. Neat. I'll give it a go. Thanks for doing this on your birthday.
 
Downloaded uncle Gizmos demo, I should be able to make sense of it. Thanks to all forum members who assisted me.
 

Users who are viewing this thread

Back
Top Bottom