5 Replies Latest reply on Sep 26, 2014 3:15 PM by Daniel Andersson

    Macro not working after adding date picker

    Feroz Mahomed

      I downloaded the attached macro and made some modifications to suit myself. The macro has stopped working after adding a date picker to select delivery date.  Please help with debugging as I don't have much vb knowledge.

        • Re: Macro not working after adding date picker
          Daniel Andersson

          CustProp - userform

          Found out that you most likely have removed a object named DelD1. But you are still trying to push and pull data to it.

          So one the error is in the CustProp userform in the code for the UserForm_Initialize(). I also found out that you do not have a variable called CheckDelD1 as well.



          ' Establishes fields and their values

            PartNum1.Text = CheckPartNumber

            Orig2.Text = CheckOrig2

            CurV1.Text = CheckCurV

            Orig1.Text = CheckOrig

            DrawD1.Text = CheckDrawD

            DelD1.Text = CheckDelD1 ' This has to be handled different. Since the value could be blank or from file. If statement needed.

            Material1.Text = CheckMat

            Drawn1.Text = CheckDrawn


          This is also happening for the Save_Click()

          ' Get custom properties from textboxes

            Properties(0) = PartNum1.Text

            Properties(1) = Orig2.Text

            Properties(2) = CurV1.Text

            Properties(3) = Orig1.Text

            Properties(4) = DrawD1.Text

            Properties(5) = DelD1.Text 'Change DelD1.Text to be DTPicker1.Value

            Properties(6) = Material1.Text

            Properties(7) = Drawn1.Text


          For some reason you also try to populate the removed object DelD1 when the user clicks on the DTPicker1. This method (Sub should be removed completly)

          Private Sub DTPicker1_Click()

          DelD1.txt = Format(Str(DTPicker1.Date), "dd,mm,yyyy")

          End Sub


          Last thing I noted in the CustProp userform is that the custom properties is not being passed on to the userform from the module. You have to check and make sure that each one of the needed variables is correct in the UserForm_Initialize. Noted that they are currently different in the Macro11 module where they are declared.

          Macro11 - Module

          Finally I found another error in the Module11, Sub CheckProps

          Sub CheckProps()

          ' Get custom properties
            CheckDieNumber = CurrentDoc.CustomInfo2("", "Die Number") ' get current PN
            CheckPlant = CurrentDoc.CustomInfo2("", "Plant") ' get current description
            CheckFileN = CurrentDoc.CustomInfo2("", "File Name") ' get current Revision
            CheckPress = CurrentDoc.CustomInfo2("", "Press") ' get current originator
            CheckDrawD = CurrentDoc.CustomInfo2("", "Drawn Date") ' get current Drawn Date
            CheckDelD = CurrentDoc.CustomInfo2("", "Delivery Date") ' get current finish  "Delivery Date" does not exist nor is created by the macro, Change it to be "Del Date". Same as found in the Main sub...
            CheckBolster = CurrentDoc.CustomInfo2("", "Bolster") ' get current material
            CheckCavities = CurrentDoc.CustomInfo2("", "Cavities") ' get current drawn

          Call EnterConfigGenProps

          End Sub


          Hope this helps, I do not know what more the macro should do... So I leave the rest to test run to you.

          I also attached the macro file with the modifications I did.

          Last note:

          What this Macro is doing is possible to do with a custom property template using the Property Tab Builder. I made a sample of how it would look like using the custom property tab instead.

          I also attached the template file. Please note that you have to change the file locations from where the template gets the lists of Plant and Press. File locations currently just set to be C:\



          Please mark this answer as correct if it helped you.

          // Daniel

            • Re: Macro not working after adding date picker
              Feroz Mahomed



              Sorry for the late response. We had a holiday on Wednesday here. I managed to make the changes as per your suggestion and the macro works fine now. Could you explain to me what the purpose of an ini file is? Would the macro work without an ini file?

              I have also made a template with the property tab builder but I have over 20 custom properties. One cannot see all the properties on the screen at once. That's why I prefer using a form.

                • Re: Macro not working after adding date picker
                  Daniel Andersson

                  The common purpose of an ini file is to store settings to programs. They can also be used to store data in. Usually they do have some syntax...


                  Example of ini file from Wikipedia:

                  ; last modified 1 April 2001 by John Doe
                  name=John Doe
                  organization=Acme Widgets Inc.
                  ; use IP address in case network name resolution is not working

                  This was the way settings was stored before the windows registry came. INI files is still used but not to that extent as in the past. Today there is options as well to the ini file and to the windows registry file. Data and settings can be stored in XML files.


                  So in your case I would not really call them ini files since they actually do not contain anything else than a few rows of data. You could call then whatever.txt since the ini file is basically just a text file. The two files could also be merged by changing the code a bit. It is good to keep data that you plan to update often and from other tools (excel etc.) in a external file, it might ease the copy paste process. Rather than having everything defined in the macro. I noted that the macro you have is settings some default values if the files is not found... maybe a scenario to think about.


                  The property tab could have multiple Groupboxes that is collapsed or expanded as defualt. That gives you the option to have a groupbox at the top with these attribute. Below you could have a second groupbox with the other attributes. That would make it quite clear and differentiate the attributes in the property tab.


                  Not saying what you should do or not. Just giving some options.

                    • Re: Macro not working after adding date picker
                      Feroz Mahomed



                      Thank you for the input. I would really like to learn VB so that I can try making my own api's in SolidWorks.

                        • Re: Macro not working after adding date picker
                          Daniel Andersson

                          VB = Visual Basic (and today I would say VB.net)

                          VBA = Visual Basic for Applications (Used for Macros is Windows applications, excel, SolidWorks etc etc etc.)


                          The macro you are working on is VBA which is quite different from VB.net. If you like to learn more about VBA and SolidWorks API you could have a look at Cadsharp.com

                          VBA is on a basic level same stuff between different applications, thinking of IF statements, Do, While, Arrays etc. The difference is the referenced libraries that is being used for different applications. So if you are quite well oriented on a basic level you could then focus alot easier on the application specific stuff (API).


                          Google around abit and do not be afraid of looking at MSDN pages or at stackoverflow.com for answers.


                          I feel that digging into programming is fun and challenging. But I feel it is difficult to maintain the knowledge since I usually do not use it on a daily basis. So it is important to keep going in order to be develop skills and keep the knowledge...