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

    Search Table for value and if not there it saves data

    Afternoon all.

    Sorry for 2nd question in the day. Atleast i solved the first one myself

    I have done some searching online and the code i am looking for has sooooo many variations that i am failing to find one that works and that i understand.

    Looking for some code that Searches "Tbl_Category" in Field "Category" for a value that is manually entered into "Frm_New_Category"

    all i am looking for is the if statement, If the value exists a message pops up saying it exists already. If it does not exist it will move onto the code that i already have in place to save what i need it to.

    The code i am using to save the textbox value is as follows.


    Code:
    Private Sub CmdBtn_Save_Click()
    
    Dim rs As Recordset
      Set rs = CurrentDb.OpenRecordset("Tbl_Category")
    
    
    With rs
      .AddNew
        !Category = Me.Textbox_New_Category
      .Update
    End With
    
    
    Me.Textbox_New_Category.Value = ""
    
    
    Me.Requery
    Me.Refresh
    
    
    End Sub

    Thanks in advance

  2. #2
    Danielt949 is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2023
    Posts
    13
    Another one solved. Code below for those that may fall into the same situation

    Code:
    If IsNull([YourTextBoxName]) or [YourTextBoxName] = "" Then
         MsgBox "Your text box is empty"
    Else
         MsgBox "Your text box is not empty" End If

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You seem intent on doing everything unbound.
    You will get easier results if you work the way Access expects you to work, that is with bound forms.

    You are just creating work for yourself.
    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. Replies: 1
    Last Post: 06-20-2019, 03:35 PM
  2. Replies: 7
    Last Post: 02-08-2014, 12:31 PM
  3. saves data with out click "Save" button in forms
    By terrythomasvda in forum Forms
    Replies: 4
    Last Post: 01-14-2013, 01:31 PM
  4. Replies: 3
    Last Post: 03-09-2012, 09:00 AM
  5. Replies: 9
    Last Post: 02-19-2010, 12:07 PM

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