New in Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • litson
    New Member
    • Nov 2009
    • 1

    New in Access

    Hi everyone,

    I would like to ask the right syntax in declaring a SQL in VBA (using access).
    I am new to access and still learning.

    I created a form and inside it has a subform now my question is.
    How can I append/insert around 12 records in my subform just clicking a button? Is my question clear?
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    Your question is clear but a bit too big to answer in a forum environment.
    What you need to do is go through some basic tutorials for access.

    Throw "ms access tutorial" into google and you will find a gazillion of them.
    If you come accross something you don't understand then post back.
    Don't try to write an actual project first up.
    Focus on understanding the basic metodology.

    Create a table
    create a query on that table
    create a form on that query so that you can add/update records from the form

    There are millions of variants of that basic process.
    Fortunately for you, access will automatically handle much of the nasty stuff for you.
    At least, it will untill you advance to the point that you don't need access to handle it for you.


    To answer your question...sort of.
    on the bottom of the subform you should have a button with an asterisk in it.
    That is the add new record button (providing your subform is correctly bound to the table and the main form

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      Originally posted by litson
      I would like to ask the right syntax in declaring a SQL in VBA (using access).
      When working on SQL from within VBA what you need is a string (generally using a variable is best) that is the properly formatted SQL and some code to execute the SQL string when you have it. There are other variations but I generally just use
      Code:
      Call DoCmd.RunSQL(strSQL)
      Originally posted by litson
      I created a form and inside it has a subform now my question is.
      How can I append/insert around 12 records in my subform just clicking a button?
      Building on from your earlier question, you need to create a SQL string of your APPEND query in an event procedure triggered by the Click event of the Command Button. When the SQL is ready in the string then execute it as above. To avoid potential warning messages (informing you of how many records to be appended etc) you can surround the code with :
      Code:
      Call Docmd.SetWarnings(False)
      ...
      Call Docmd.SetWarnings(True)

      Comment

      • Delerna
        Recognized Expert Top Contributor
        • Jan 2008
        • 1134

        #4
        Oh....I see, I totally misread the question :-S

        Comment

        • topher23
          Recognized Expert New Member
          • Oct 2008
          • 234

          #5
          Originally posted by NeoPa
          Code:
          Call DoCmd.RunSQL(strSQL)
          FYI, if you don't wrap your string in parentheses, you don't need to Call the function.
          Code:
          DoCmd.RunSQL strSQL
          This works for most functions except when you set something equal to the function's result, for example
          Code:
          intResult = MsgBox("Do you want to continue?", vbYesNo)

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            You don't need to use the Call keyword, but as the syntax in VBA is so ambiguous, and there is nothing else that immediately tells a reader that the code is calling a procedure, it's probably wise to anyway.

            Besides, as functions are designed to return values (as opposed to subroutines which aren't), using a form which cannot be used consistently and in the normal usage of the function procedure, seems a little bizarre to me. I know MS provided the kludgy interface, just as they provide the option for using variables that have never been declared, but that's no reason to use it surely.

            Comment

            Working...