首先保证终止段号码大于起始段号码。把所有的数据取出来逐条比较:
if (起始段号码<记录集中起始段号码 and 终止段号码>记录集中起始段号码) or (起始段号码<记录集中终止段号码 and 终止段号码>记录集中终止段号码) then
    msgbox "区段号码重叠!",,"错误!"
end if

解决方案 »

  1.   

    对不起,条件写错了!——修改如下:(起始段号码<记录集中起始段号码 and 终止段号码>记录集中终止段号码) or (起始段号码>记录集中起始段号码 and 起始段号码<记录集中终止段号码) or (终止段号码>记录集中起始段号码 and 终止段号码<记录集中终止段号码)
      

  2.   

    这样,将数据库中所有记录读出来,逐条比较。If Trim(Text1.Text)>起始段 Or Trim(Text2.Text)<终止段 Then
        Msgbox  "区段已存在,请检查后重新输入"
      

  3.   

    错了,少了End If。
    改为
    If Trim(Text1.Text)>起始段 Or Trim(Text2.Text)<终止段 Then
        Msgbox  "区段已存在,请检查后重新输入"
    End If
      

  4.   


    楼上的,你这样写不对。还有几种区域重叠的情况没有考虑:
    (Trim(Text1.Text)<起始段 AND Trim(Text2.Text)>终止段)
    我上面的已经写全了。
      

  5.   

    把这个比较使用存储过程的话效率更高create proc JudgeNum (
      @min_num varchar(10),
      @max_num varchar(10),
      @NumResult int output)
    as
    begin
      if (select count(*) as num from 表 where (startpos<@min_num and stoppos>@min_num) or (startpos<@max_num and stoppos>@max_num))>1 
        return 1
      else
        return 0
    end 
    go
    '返回1表示界定的范围已经有了
    '0表是没有我这里没有装sql,不能测试,反正思想就是这样,呵呵!