Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Access Person Cannot Write Insert Query In Alpha

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Access Person Cannot Write Insert Query In Alpha

    OK, I am too used to the query genies in Access and have trouble rewriting sql queries that will work in Alpha.

    In Access, the SQL view of an INSERT query is below. In my query, I am appending (or inserting) multiple records with a JOB_CODE of H to the same
    table but with a JOB_CODE from the form I'm on. In other words, I am copying all records from H job to another job.
    I named the field to append to JOB_CODE JOB with reference to Forms!FrmJobSetupNewJobs!JOB_CODE. Here's the SQL view from Access:
    Code:
    INSERT INTO TblJobsPriorityMeasures ( JOB_CODE, MEASURE, QUANTITY, PRIORITY_NUM )
    SELECT Forms!FrmJobSetupNewJobs!JOB_CODE AS JOB, TblJobsPriorityMeasures.MEASURE, TblJobsPriorityMeasures.QUANTITY, TblJobsPriorityMeasures.PRIORITY_NUM
    FROM TblJobsPriorityMeasures
    WHERE (((TblJobsPriorityMeasures.JOB_CODE)="H"));
    In Alpha, the above syntax does not work, of course, so I have tried several iterations, but not surprisingly, none of them work.
    Here's one of them:

    Code:
    dim jobCode as c 
    jobCode = e.session.specsJobCode
    
    dim sqlInsertStatement as c
    
    dim args as sql::arguments
    args.add("JOB_CODE",jobCode)
    args.add("HJob","H")
    
    sqlInsertStatement = <<%sqltxt%
    INSERT INTO TblJobsPriorityMeasures (JOB_CODE, MEASURE, QUANTITY, PRIORITY_NUM) VALUES (SELECT :JOB_CODE as JOB_CODE, MEASURE, QUANTITY, PRIORITY_NUM FROM TblJobsPriorityMeasures WHERE JOB_CODE = :HJob)
    %sqltxt%
    
    cn.Execute(sqlInsertStatement,args)   (etc., etc.)
    Any suggestions?
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

    #2
    Re: Access Person Cannot Write Insert Query In Alpha

    This works for me...

    sql1 = "Insert into employees (DateCreate, FirstName, LastName) Values(:DateCreate,:FirstName,:LastName)"

    flag = e.cn.execute(sql1,args)

    Comment


      #3
      Re: Access Person Cannot Write Insert Query In Alpha

      Thank you, Ivasic. I have used a simple single record insert like you showed several times successfully in Alpha. But this is now a more complex insert query where I need to insert multiple records that are copies of other records selected from a table with a WHERE clause, etc.
      Carol King
      Developer of Custom Homebuilders' Solutions (CHS)
      http://www.CHSBuilderSoftware.com

      Comment


        #4
        Re: Access Person Cannot Write Insert Query In Alpha

        dim jobCode as c
        jobCode = e.session.specsJobCode

        dim sqlInsertStatement as c

        dim args as sql::arguments
        args.add("JOB_CODE",jobCode)
        args.add("HJob","H")----------------why is there "" around the H

        sqlInsertStatement = <<%sqltxt%
        INSERT INTO TblJobsPriorityMeasures (JOB_CODE, MEASURE, QUANTITY, PRIORITY_NUM) VALUES (SELECT :JOB_CODE as JOB_CODE, MEASURE, QUANTITY, PRIORITY_NUM FROM TblJobsPriorityMeasures WHERE JOB_CODE = :HJob)
        %sqltxt%

        cn.Execute(sqlInsertStatement,args) (etc., etc.)


        Also does the sqltxt need to be evaluated?
        where are the open cn and close?
        Chad Brown

        Comment


          #5
          Re: Access Person Cannot Write Insert Query In Alpha

          If I understand what you're doing. Inserting into the same table.
          The SQL should be like this:

          insert into TblJobsPriorityMeasures
          (JOB_CODE,MEASURE,QUANTITY,PRIORITY_NUM)
          Select JOB_CODE = 'B',MEASURE,QUANTITY,PRIORITY_NUM
          From TblJobsPriorityMeasures where JOB_CODE = 'A'

          Comment


            #6
            Re: Access Person Cannot Write Insert Query In Alpha

            I just tried this (without arguments and removing them from execute statement) and I get an error message that there are too few parameters. (jobCode is a variable established earlier)

            Code:
            INSERT INTO TblJobsPriorityMeasures
             (JOB_CODE, MEASURE, QUANTITY, PRIORITY_NUM) 
            SELECT JOB_CODE = jobCode, MEASURE, QUANTITY, PRIORITY_NUM 
            From TblJobsPriorityMeasures where JOB_CODE = 'H'
            Chad - I was just evaluating the statement because earlier when I learned how to do a simple insert query, Selwyn had given me an example where the statement was evaluated. In this thread, I left out the code about opening and closing the connection, etc., because I just wanted to show the part of the code that had the issue. I have been using double quotes around character arguments in a lot of my arguments for sql queries, and they have worked. I don't know for sure if they are needed or not now. I think when I didn't have them in prior days, I got an error, but who knows... my brain is fried with this.
            Carol King
            Developer of Custom Homebuilders' Solutions (CHS)
            http://www.CHSBuilderSoftware.com

            Comment


              #7
              Re: Access Person Cannot Write Insert Query In Alpha

              INSERT INTO TblJobsPriorityMeasures (JOB_CODE, MEASURE, QUANTITY, PRIORITY_NUM)
              VALUES (SELECT JOB_CODE ='jobCode', MEASURE, QUANTITY, PRIORITY_NUM )
              From TblJobsPriorityMeasures where JOB_CODE = 'H'
              Chad Brown

              Comment


                #8
                Re: Access Person Cannot Write Insert Query In Alpha

                Finally got it to work! I had to use argument for the job code AND it needed Select :JOB_CODE AS JOB_CODE


                Code:
                dim jobCode as c 
                jobCode = e.session.specsJobCode
                
                dim sqlInsertStatement as c
                
                dim args2 as sql::arguments
                args2.add("JOB_CODE",jobCode)
                
                sqlInsertStatement = "INSERT INTO TblJobsPriorityMeasures (JOB_CODE, MEASURE, QUANTITY, PRIORITY_NUM) SELECT :JOB_CODE AS JOB_CODE, MEASURE, QUANTITY, PRIORITY_NUM From TblJobsPriorityMeasures where JOB_CODE = 'H'"
                
                cn.Execute(sqlInsertStatement,args2)
                Carol King
                Developer of Custom Homebuilders' Solutions (CHS)
                http://www.CHSBuilderSoftware.com

                Comment


                  #9
                  Re: Access Person Cannot Write Insert Query In Alpha

                  Also, just went and put the argument back in for getting the H job code for the where part of the sql statement and that worked, too. (I'm told it's best to use arguments for all criteria.) So, really I was just messing up in my first example by using VALUES in the sql statement. Plain English, I wanted to copy records that had a JOB_CODE of 'H' to another JOB_CODE that had been captured as a session variable.

                  Code:
                  dim jobCode as c 
                  jobCode = e.session.specsJobCode
                  
                  dim sqlInsertStatement as c
                  
                  dim args2 as sql::arguments
                  args2.add("JOB_CODE",jobCode)
                  args2.add("HJob","H")
                  
                  sqlInsertStatement = "INSERT INTO TblJobsPriorityMeasures (JOB_CODE, MEASURE, QUANTITY, PRIORITY_NUM) SELECT :JOB_CODE AS JOB_CODE, MEASURE, QUANTITY, PRIORITY_NUM From TblJobsPriorityMeasures where JOB_CODE = :HJob"
                  
                  cn.Execute(sqlInsertStatement,args2)
                  Carol King
                  Developer of Custom Homebuilders' Solutions (CHS)
                  http://www.CHSBuilderSoftware.com

                  Comment


                    #10
                    Re: Access Person Cannot Write Insert Query In Alpha

                    Also, just to clarify... This code will update the entire database. If you have 100 records with "H" this will insert 100 new records...

                    Comment


                      #11
                      Re: Access Person Cannot Write Insert Query In Alpha

                      Yes, Ivasic, that's absolutely right. In my case, a builder is copying spec measurements from job to another. There is also a count query prior to the insert query that checks to make sure that the job being copied to has no spec measurements. If there are none, then the insert query is allowed. If some are found, the insert query is not allowed.
                      Carol King
                      Developer of Custom Homebuilders' Solutions (CHS)
                      http://www.CHSBuilderSoftware.com

                      Comment


                        #12
                        Re: Access Person Cannot Write Insert Query In Alpha

                        I read with interest Carol�s thread about having trouble writing an INSERT query in Alpha 5, as I have been struggling with this for a few weeks now (learning a lot, fixing a lot along the way, but at the end of the road and not sure how to proceed for here). Ultimately I am looking to execute an insert statement from another set of tables with joins and parameters. However, I have worked back to a more basic query for troubleshooting and can�t even get this to work.
                        Here is my code (in the AfterSearch event):
                        HTML Code:
                        function AfterSearch as v (SearchDataSubmitted as P, Args as p, PageVariables as p)
                        with PageVariables
                        dim aa as p 
                        dim TimePeriod AS D
                        dim SearchID as c
                        dim EmpID AS C
                        dim numrec as c
                        TimePeriod=SearchDataSubmitted.TimePeriodDate
                        EmpID="FAH600"
                        SearchID="vHOL"
                        aa = args.rtc.A_AjaxResponses
                        aa[].text =	 "alert('EmpID: "+ EmpID +" TimePeriod: "+TimePeriod+"SearchID: "+ SearchID+"');"
                        aa[..].id = 100  'the order in which AjaxResponses are sent to the browser
                        
                        'Insert a new record into a remote SQL database.
                        'DIM a connection variable
                        dim cn as SQL::Connection
                        'Dim a SQL arguments object, create arguments and set their values
                        dim K_args as sql::arguments
                        
                        K_args.add("EmpID",EmpID)
                        K_args.add("SearchID",SearchID)
                        K_args.add("TimePeriod",TimePeriod)
                        
                        dim sqlInsertStatement as c 
                        sqlInsertStatement = "INSERT INTO TimeEntryTEMP(EmpID,SearchID,TimePeriodDate) SELECT :EmpID as EmpID,:SearchID as SearchID,:TimePeriod as TimePeriodDate from tblTimeEntry"
                        
                        cn.Execute(sqlInsertStatement,K_args)
                        cn.close()
                        
                        end with
                        end function
                        I also tried inserting values only :

                        HTML Code:
                        sqlInsertStatement = "INSERT INTO TimeEntryTEMP(EmpID,SearchID,TimePeriodDate) ('FAH600','VSICK','1/15/2027')"
                        Finally I also tried SELECT DISTINCT.

                        This hasn�t worked; nor has using the Genies/portable SQL.
                        I�ve re-written the grid to be very basic (on a table);
                        added in the variable msg box to show me what the variables are being populated with;
                        I have also manually added records to the TimeEntryTEMP table on the control panel with no problem;
                        Have added records via the grid itself .. no problem.
                        I can also write the INSERT query in SQL Express without issue..
                        Other things to note: the 3 fields are indeed primary keys and don�t allow nulls; have checked for duplicates, etc and they are fine.


                        If anyone sees what I am missing, I would so appreciate it! I definitely feel stupid,and this week I have learned how valuable this forum is, so I�m hoping someone out there will see what I cannot! Any advice would be so appreciated � hope to get some sleep this week!

                        Comment


                          #13
                          Re: Access Person Cannot Write Insert Query In Alpha

                          I put the code here in the event (onBeforeSQLCommandExecute)
                          The code will look like this. Are you updating one record?
                          sqlInsertStatement =
                          INSERT INTO TimeEntryTEMP(EmpID,SearchID,TimePeriodDate)
                          Values(:EmpID,:SearcID,:TimePeriod)

                          Comment


                            #14
                            Re: Access Person Cannot Write Insert Query In Alpha

                            sqlInsertStatement = "INSERT INTO TimeEntryTEMP(EmpID,SearchID,TimePeriodDate) ('FAH600','VSICK','1/15/2027')"

                            Date format in sql needs to be '2027/1/15' also where is the values?

                            Try this instead

                            INSERT INTO TimeEntryTEMP(EmpID,SearchID,TimePeriodDate) VALUES('FAH600','VSICK','2027/1/15')
                            Last edited by chadbrown; 09-21-2011, 01:24 PM.
                            Chad Brown

                            Comment


                              #15
                              Re: Access Person Cannot Write Insert Query In Alpha

                              You guys are great: thank you for your quick replies! I have to say, though, i am still stuck:

                              Here are both code functions that i just tried:
                              HTML Code:
                              function AfterSearch as v (SearchDataSubmitted as P, Args as p, PageVariables as p)
                              with PageVariables
                              dim aa as p 
                              dim TimePeriod AS D
                              dim SearchID as c
                              dim EmpID AS C
                              dim numrec as c
                              TimePeriod=SearchDataSubmitted.TimePeriodDate
                              EmpID="FAH600"
                              SearchID="vHOL"
                              'Insert a new record into a remote SQL database.
                              'DIM a connection variable
                              DIM cn as SQL::Connection
                              
                              aa = args.rtc.A_AjaxResponses
                              aa[].text =	 "alert('EmpID: "+ EmpID +" TimePeriod: "+TimePeriod+"SearchID: "+ SearchID+"');"
                              aa[..].id = 100  'the order in which AjaxResponses are sent to the browser
                              
                              'Dim a SQL arguments object, create arguments and set their values
                              DIM K_args as sql::arguments
                              
                              K_args.add("EmpID",EmpID)
                              K_args.add("SearchID",SearchID)
                              K_args.add("TimePeriod",TimePeriod)
                              
                              dim sqlInsertStatement as c 
                              sqlInsertStatement = "INSERT INTO TimeEntryTEMP(EmpID,SearchID,TimePeriodDate) VALUES(:EmpID,:SearchID,:TimePeriod)"
                              
                              cn.Execute(sqlInsertStatement,K_args)
                              cn.close()
                              
                              end with

                              HTML Code:
                              function AfterSearch as v (SearchDataSubmitted as P, Args as p, PageVariables as p)
                              with PageVariables
                              dim aa as p 
                              dim TimePeriod AS D
                              dim SearchID as c
                              dim EmpID AS C
                              dim numrec as c
                              TimePeriod=SearchDataSubmitted.TimePeriodDate
                              EmpID="FAH600"
                              SearchID="vHOL"
                              'Insert a new record into a remote SQL database.
                              'DIM a connection variable
                              DIM cn as SQL::Connection
                              aa = args.rtc.A_AjaxResponses
                              aa[].text =	 "alert('EmpID: "+ EmpID +" TimePeriod: "+TimePeriod+"SearchID: "+ SearchID+"');"
                              aa[..].id = 100  'the order in which AjaxResponses are sent to the browser
                              'Dim a SQL arguments object, create arguments and set their values
                              DIM K_args as sql::arguments
                              K_args.add("EmpID",EmpID)
                              K_args.add("SearchID",SearchID)
                              K_args.add("TimePeriod",TimePeriod)
                              dim sqlInsertStatement as c 
                              sqlInsertStatement = sqlInsertStatement = "INSERT INTO TimeEntryTEMP(EmpID,SearchID,TimePeriodDate) ('FAH600','VSICK','1/15/2027')"
                              
                              cn.Execute(sqlInsertStatement,K_args)
                              cn.close()
                              
                              end with
                              end function
                              No luck on either of them. Ultimately, what i am trying to get to is that whenever the user uses the search drop down box, a query is run against a few tables in my db (not the grid source);a few filters are applied, then the resultset (could be 0-40 records) is appended to the table that the grid is sourced against. So i think i have to leave the code in AfterSearch: do you think this is part of the issue? I also wondered abut the date format, but there has to be something else i think, b/c hardcoding the date as above didn't update my table. (and again i can go to control panel and update it np, so i think the SQL design is ok?)

                              THank you so much! It helps to validate - i have no idea what the issue could be - will try the port sql flag next, i wonder if i am missing a major setting somewhere as well. such a Rookie!

                              Comment

                              Working...
                              X