+ Reply to Thread
Results 1 to 4 of 4

writing userform input to database

  1. #1
    Registered User
    Join Date
    04-08-2015
    Location
    Belgium
    MS-Off Ver
    Office 2013
    Posts
    51

    writing userform input to database

    Hi,

    I wrote an accounting program in excel VBA, linked with products (sale and buy etc.).
    The problem I currently encounter is that I have too many products to store in Excel spreadsheets, so I started re-writing it in in access.

    I already searched the intrnet for some hour, but I'm still stuck at some very basic stuff. I have a userform which needs to write a new record to the database.

    Layout of the database:
    Table name = Klanten
    Field 1 of Klanten is 'ID'
    Field 2 of Klanten is 'Klantnaam'

    The current code I have is:

    Please Login or Register  to view this content.
    Could anyone please shine some light on this, as it's the very basic thing I need to know before I can continue.
    I prefer using access for everything instead of using excel linked with access.

    Thanks!

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: writing userform input to database

    A couple of issues:
    • Klantnaam is declared as 'Integer' but you are assigning the value of a textbox to it. Maybe Access will coerce the textbox contents to an Integer but I doubt it. The line 'klantnaam = txtKlantnaam.Text' will probably throw an error unless Klantnaam is declared as a string
    • You cannot access the .Text property of a control in Access unless that control has focus. Use the .Value property if you do not want to set focus to the control first.
    • rst & db are Objects, to destroy them you must use the Set keyword.

    Your original code updated:

    Please Login or Register  to view this content.
    Although, to make things easier Access can handle all this using the following:
    Please Login or Register  to view this content.
    2 extra fields were added as examples of inserting different data types.


    sql.jpg
    Last edited by cytop; 11-13-2016 at 07:50 AM. Reason: Image attached

  3. #3
    Registered User
    Join Date
    04-08-2015
    Location
    Belgium
    MS-Off Ver
    Office 2013
    Posts
    51

    Re: writing userform input to database

    Hi,

    Appreciate the fast answer.
    I tried both methods, but my table Klanten isn't updating, no records are being written to it. Maybe I did something wrong in the userform I'm not sure, I attached it.
    Could you please have a look at it?
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: writing userform input to database

    I can't stand those embedded macros in Access, and that is what was called on the button click. Change it to call an 'Event Procedure' (Click the Down Arrow to the right of the Click event for the button in the Properties dialog) then click the Ellipses (...) to the right of that.

    Doing that will open an event stub for the click event. The full code, including the correct field names, is below.

    FFS - this firewall is a PITA. Code in attachment - right click the button in design View, select 'Build Event' to view the code.
    Attached Files Attached Files
    Last edited by cytop; 11-13-2016 at 10:44 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Input Filtered DataBase into Userform Listbox by clicking cmd
    By brainzlp in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-07-2016, 01:27 PM
  2. Writing to SQL Database from Excel
    By martinpgibson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-15-2014, 12:46 AM
  3. Multiple Users input data using Excel Userform to a Common Access Master Database
    By eummagic in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-08-2014, 01:45 AM
  4. [SOLVED] Writing row to a database
    By TubbzUK in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-12-2013, 08:59 PM
  5. Search Through Database And Display Results In Userform without showing database
    By nirvanarapeme in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-04-2012, 05:18 PM
  6. Writing a Formula based on UserForm input
    By MichelleW in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2009, 11:15 AM
  7. Writing to a database using VBA
    By matpj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2007, 11:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1