Results 1 to 3 of 3
  1. #1
    database_1 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2020
    Posts
    34

    Delete code not recognizing my string values

    I have a form where a user uses a combobox to pick a position, then use another combobox to pick a training. Then there is a button to delete the selected training. For some reason when I try to run this code, it asks for a value for pos but there is an option chosen in the pos_cmb. Why is this happening and how could I fix it?

    Dim trng As String
    Dim pos As String
    pos = Me.cmb_pos.Value
    trng = Me.com_trng.Column(1)
    MsgBox (trng)


    DoCmd.SetWarnings False
    strSQL = "Delete * From [TRNG_TBL] WHERE [POS_ID] = pos And [TRNG_ID] = trng"
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings True

    End Sub

  2. #2
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Try this:
    Code:
    strSQL = "Delete * From [TRNG_TBL] WHERE [POS_ID] = '" & pos & "' And [TRNG_ID] = '" & trng & "'"
    Note the single quotes needed for string variables (none for numbers and # for dates).
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    As Vlad shows, must concatenate variable inputs.

    You declared variables as string type. Are the fields text data type?

    The variables are not really needed since they are used only once. Why annoy users with message box?

    I prefer Execute method then don't need SetWarnings.

    If the fields are actually number type:

    CurrentDb.Execute "DELETE FROM [TRNG_TBL] WHERE [POS_ID] =" & Me.cmb_pos & " AND [TRNG_ID] = " & Me.cmb_trng
    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: 6
    Last Post: 10-29-2018, 06:41 AM
  2. Replies: 7
    Last Post: 09-16-2017, 04:01 PM
  3. Delete Partial String HELP!!
    By Crawfordrider33 in forum Access
    Replies: 2
    Last Post: 05-15-2015, 11:31 AM
  4. Replies: 2
    Last Post: 04-05-2015, 06:06 PM
  5. Replies: 3
    Last Post: 10-30-2014, 08:45 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