Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

开发平台上的“保存”VBA求助

justinliao  发表于:2018-01-08 15:20:32  
复制

求助老师, 

以下红色字体是我增加的代码,现在保存输入 Me.PGqty数据时,不管有没有超出规定值,点保存时都会体现保存成功!另外,如何做到当输入Me.PGqty时先判断是否strFqty +Me.PGqty)> strZqty,如果是则数据不可保存,且会提示超过数量值?谢谢


Private Sub btnSave_Click()

    On Error GoTo ErrorHandler
    
    If Not CheckRequired(Me) Then Exit Sub
    If Not CheckTextLength(Me) Then Exit Sub

    Dim cnn: Set cnn = GetADOConnection()


   'cnn.BeginTrans
   'Dim blnTransBegin As Boolean: blnTransBegin = True


    Dim strSQL: strSQL = "SELECT * FROM [lblproductreport_group] WHERE [No]=" & Nz(Me![No], 0)
    Dim rst:    Set rst = ADO.OpenRecordset(strSQL, adLockOptimistic, cnn)
    If rst.EOF Then rst.AddNew
    UpdateRecord Me, rst
    '你的自定义代码
    'rst!Field1 = Me!Field1
    'rst!Field2 = Me!Field2
    rst.Update
    rst.Close
    Dim strZqty: strZqty = DLookup("ZLqty", "lblzlcode", "ZLID='" & Me.ZLID & "'")
    Dim strFqty: strFqty = DLookup("Totalqty", "qryzlfinish_totalqty", "ZLID='" & Me.ZLID & "'and SID='" & Me.SID & "'")
    Dim strUFqty: strUFqty = DLookup("unfinishqty", "qryzlunfinish_qty", "ZLID='" & Me.ZLID & "'and SID='" & Me.SID & "'")


    If strFqty <= strZqty Then
    Me.AllowAdditions = True
    End If
    
    If strFqty > strZqty Then
    MsgBox (strUFqty - Me.DataEntry)
      If MsgBox("你刚录入的数据大于订单量,请重新录入", vbOKCancel, "提示") = vbOK Then
      Me.AllowAdditions = False
      Me.PGqty = ""
     
      End If
     Exit Sub
    End If
    
   'cnn.CommitTrans
   'blnTransBegin = False


    RequeryDataObject gsfrList
    MsgBoxEx LoadString("Saved Successfully."), vbInformation
       
    If Me.DataEntry Then
        Me.InitData
    Else
        DoCmd.Close acForm, Me.Name, acSaveNo
    End If
    
    
ExitHere:
    Set rst = Nothing
    Set cnn = Nothing
    
    Exit Sub


ErrorHandler:
   'If blnTransBegin Then
   '    cnn.RollbackTrans
   '    blnTransBegin = False
   'End If
    RDPErrorHandler Me.Name & ": Sub btnSave_Click()"
    Resume ExitHere
End Sub

 

Top
MDZZ 发表于:2018-01-09 08:55:29

保存代码设置Me.AllowAdditions   不知道有什么意义   数据应该在保存前面判断吧 

快速开发平台2.3--新增修改功能代码详解[Access软件网] http://www.accessoft.com/article-show.asp?id=16407



yihui 发表于:2018-01-09 17:06:01


justinliao 发表于:2018-01-10 21:07:33

请教下面这个语句要如何修改:

 If strUFqty - Me!PGqty < 0 Then
    MsgBox (strUFqty - Me!PGqty)
    rst!PGqty = ""        ‘当小于0时,要清空刚才输入的值,且不能保存
      ElseIf strUFqty - Me!PGqty >= 0 Then 
      rst!PGqty = Me!PGqty    ‘当符合这个条件时,输入可以保存
      End If



总记录:3篇  页次:1/1 9 1 :