Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004

    Unanswered: Need to alter my code to allow for integer values

    Hello, I have the following code which checks wether a field value in a combo box is being used in another table. If the value is being used, a message informs the user that the value is in use and it cannot be deleted.

    The code checks for string values.

    I need it however to check for number (integer) values.

    I cannot get it to work with integer values, is it the bracketing? What do I need to alter?
    Dim delRS As Recordset, strSQL As Integer
    strSQL = "select tblVisits.centreID FROM tblVisits WHERE (((tblVisits.centreID)='" & [Forms]![visits_frm]![Combo160] & "'));"
    Set delRS = CurrentDb.OpenRecordset(strSQL)
    If delRS.RecordCount > 0 Then
    MsgBox "You cannont delete this location at this time because it is related to another resource on the database."
    Exit Sub
    End If

  2. #2
    Join Date
    Aug 2009
    Up Nort' Wi
    Is it always an integer type?
    If so just get rid of the single quotes around the text box name

    (((tblVisits.centreID)=" & [Forms]![visits_frm]![Combo160] & "));"
    Personally, I would also explicitly cast the value as an integer using the CInt(tblVisits.centreID) function

    If it can be either or (not sure why it would be) then you'll need to use a IsNumeric check before running that line.

    Sam, hth
    Good, fast, cheap...Pick 2.

  3. #3
    Join Date
    Aug 2004
    Thankyou for replying, all is sorted

  4. #4
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    explicitly cast the vlaue to the desitred dataype


    myintegervalue = cint(forms!myform!mycontrol)
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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