Results 1 to 5 of 5
  1. #1
    Danielt949 is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2023
    Posts
    13

    Textbox to add results to table

    Good afternoon all.

    New to Access and new to this site (first time poster). Ive got some experience with Excel and have learnt a little with VBA via excel.
    I have been making a fair CMMS database with Excel and i have hit some brick walls and thinking my project may be more suitable to an access platform instead.

    The project i am making, in the end i will want it looking like more of an independent system using userforms instead of having people go to all the tables when editing things.

    I have Tbl_Category, with 2 columns in the design mode, Category_ID and Category
    Category_ID is Auto numbered


    Category is a list of different categories i am going to use as the basis for the components to live under.

    I have a form "Frm_New_Category" which has "Listbox_Current_Categories", "Textbox_New_Category", CmdBtn_Close_Form and "CmdBtn_Save"

    What i am trying to achieve is to enter a "New" category into the textbox, click the save button and it adds it to "Tbl_Categories"

    I originally come up with an error with the Tbl not being opened to allow for the entry, I manually open it and the error went away, but the new Category would not save still.

    Can someone please assist in the direction i need to take?
    Is such an idea possible in Access?
    Is there a way of doing this without opening the Tbl and only use the userform so that i can maintain the long term goal of keeping the form looking like a stand-alone program via the use of userforms?

    I am trying to upload the file for your reference, however it is saying it is too big, even at its early stages. I tried the compact and repair and this did not reduce the size enough to post.

    Many thanks.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Is form is bound to Tbl_Category? What is code behind button? Why would you even need the listbox? If you want to provide db for analysis, follow instructions at bottom of my post.
    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
    Danielt949 is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2023
    Posts
    13
    Thank you for your reply.

    However i have just worked it all out. I am literally like 2 days old to Access, i was attempting to use what i think may have been the wizard for the save button. However i have now found the macro screen and was able to enter the correct macro code.

    Code:
    Dim rs As Recordset  Set rs = CurrentDb.OpenRecordset("Tbl_Category")
    
    
    With rs
      .AddNew
        !Category = Me.Textbox_New_Category
      .Update
    End With
    The purpose of the listbox is to make sure the end user is checking to see what categories are in the system before they were to enter another. Pretty much a simple userform that allows end user to customize without absolute any need to for any access knowledge. Its a database being built for mechanics, not IT guys.

    Yeah, upload document process is exactly what i was trying to attempt. Limit is 500kb i believe, My file is 620kb, Dont know why it is so big as it is still new. The upload process and forum style is identical to excelforum.net which i have been in for some period of time now.


    Thanks.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    That's one way to save data to table. Another is to use bound form and no code is needed.

    Another approach is with NotInList event of combobox to add new Category record "on the fly" during data entry - yes, this would require VBA.

    A technical point to keep in mind - the code you posted is VBA, not a macro. Macro code in Access is very different.

    Zip file with Windows Compression and attach to post. 2MB zip allowed.
    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.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by Danielt949 View Post

    The purpose of the listbox is to make sure the end user is checking to see what categories are in the system before they were to enter another. Pretty much a simple userform that allows end user to customize without absolute any need to for any access knowledge. Its a database being built for mechanics, not IT guys.
    If that is the case, then you need to ensure the new category does not exist already?, plus you would need to requery the listbox after adding the new category?
    Most people would use a combo and the NotInList event of that combo.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Return the results of a SQL query in textbox
    By virgilio in forum Access
    Replies: 5
    Last Post: 12-16-2019, 03:55 PM
  2. Display results of calculation in textbox
    By virgilio in forum Access
    Replies: 13
    Last Post: 12-06-2019, 02:47 PM
  3. Textbox needs to show query results
    By skydivetom in forum Forms
    Replies: 13
    Last Post: 10-30-2019, 10:30 AM
  4. Replies: 3
    Last Post: 10-20-2017, 03:38 PM
  5. Dsplaying query results in a textbox
    By sevanty7 in forum Access
    Replies: 2
    Last Post: 05-08-2013, 09:00 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