Results 1 to 6 of 6
  1. #1
    byulogia@gmail.com is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2019
    Location
    Papua New Guinea
    Posts
    22

    Insert into table


    I am trying to insert information into the table from the form.
    My code is:

    Currentdb.Execute "INSERT INTO Applications(AppID, FirstName,LastName,DOB,Gender,Province,Institution ") & _
    "VALUES(" & Me.AppID & ",'" & Me.FirstName & "','" & Me.LastName & "'_
    Me.DOB & "," & Me.cboGender & "','" & Me.cboProvince & "' , "' & Me.cboInstitution & '")

    It is not working.

    Please someone can able to suggest a solution or give me a correct sample code. I am a new learner.
    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Currentdb.Execute "INSERT INTO Applications(AppID, FirstName, LastName, DOB, Gender, Province, Institution") & _
    "VALUES(" & Me.AppID & ",'" & Me.FirstName & "','" & Me.LastName & "',#" & _
    Me.DOB & "#,'" & Me.cboGender & "','" & Me.cboProvince & "','" & Me.cboInstitution & "'")


    Why do you need to use VBA and INSERT to add data? Why not direct data entry to form bound to table?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    byulogia@gmail.com is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2019
    Location
    Papua New Guinea
    Posts
    22
    Thank June7.
    I can use direct entry to form bound to tables. But when I load forms, the data appears in the form, which I dont want it to. I want the form to open without data so I can continue to add data. Any ideas?

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    set the form dataentry property to true

  5. #5
    byulogia@gmail.com is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2019
    Location
    Papua New Guinea
    Posts
    22
    Ajax
    Wow, thats very simple....
    Thanks thanks

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Or leave DataEntry set to No and use VBA to open form to allow new records only. Greater flexibility to use same form for different situations.

    DoCmd.OpenForm "your form name", , , , acFormAdd

    Either way, all records created in that session will be available for edit until form is closed.

    Or use code that moves to new record row immediately when form opens. Users can still navigate existing records.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 11-19-2018, 06:53 PM
  2. Replies: 1
    Last Post: 06-12-2015, 02:02 PM
  3. Replies: 2
    Last Post: 12-20-2011, 07:33 AM
  4. Replies: 2
    Last Post: 12-22-2010, 01:46 PM
  5. Replies: 0
    Last Post: 02-24-2010, 12:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums