MS ACCESS在同一条目的多行上执行相同的代码

时间:2015-07-28 08:25:06

标签: vba

我是Access vba编程的新手,所以我真的会使用一些帮助!

所以我有一张桌子

双击B列后,它会执行代码:

    Private Sub SkleistasNr_DblClick(Cancel As Integer)
Dim rs As ADODB.Recordset
Dim rs1 As ADODB.Recordset
Set rs = New ADODB.Recordset
Set rs1 = New ADODB.Recordset

Dim strLinkCriteria As String
Dim strDocName As String
Dim a As Long

Dim b, r

DoEvents


If Me.Tipas = "MEL" Then
pGANr = Me!GANR
GautiMazgoKoda Me.UþsakymoNr
pGANr = ""

End If


If Me.Tipas = "AVS" Or Me.Tipas = "ISS" Or Me.Tipas = "EAS" Or Me.Tipas = "MEL" Then
r = Application.SysCmd(acSysCmdInitMeter, " Tikrinama schemu pasikeitimai", 10)

    'TikrintiSchema Me.UþsakymoNr
    '    If Me.PakeistaSchema = True Then
    '    b = MsgBox("Ar rodyti si pranesima sekanti karta ?", 3, "Siam uzsakymui padarytas schemos pakeitimas")
    '    If b = 7 Then
    '        Me.PakeistaSchema = False
    '    End If
    'End If
    r = Application.SysCmd(acSysCmdSetStatus, " ")
End If
Me.Refresh

a = 0
pGANr = ""
If Not IsNull(Me.Kodas) Then



strDocName = "FrUzsk1"
rs.Open "select * from tbga where ganr=" & Me.GANR, CurrentProject.Connection, adOpenDynamic, adLockOptimistic


If (rs.EOF) = False Then
    rs.MoveFirst
        If rs!Pabaiga = True And IsNull(rs!NusiustasApskaitai) Then
            a = MsgBox("Ar redaguosite sena gamybos akta? Siuo metu jis dar neperduotas tolesniam forminimui. ", vbYesNo, "Ar redaguoti paskutini gamybos akta?")
        End If
    If a = 7 Then a = a 'pGANr = GamintiToliauKiti(Me)
Else
    pGANr = Me!GANR
End If
If pGANr = "" Then pGANr = Me!GANR

        DoCmd.OpenForm strDocName, acNormal ', ("tbga.ganr=" & Me!GANr)  '"SkleistasNr =" & "'" & Me.SkleistasNr & "'")
Else
    pKodas = ""
    pGANr = Me!GANR
    MsgBox " Suveskite gaminio koda pagal atsiusta schema. Uzsakymui Nr= " & pSkleistasNr & "  " & pKodas
    DoCmd.OpenForm "Frkodavimas", acNormal
 If Me.Tipas = "SKM" Then
        Form_FrKodavimas.mp.Value = 0
 ElseIf Me.Tipas = "SKU" Then
        Form_FrKodavimas.mp.Value = 1
 ElseIf Me.Tipas = "SKS3" Then
        Form_FrKodavimas.mp.Value = 2
 ElseIf Me.Tipas = "AVS" Then
        Form_FrKodavimas.mp.Value = 3
 ElseIf Me.Tipas = "MEL" Then


 ElseIf Me.Tipas = "SDU" Then
        Form_FrKodavimas.mp.Value = 4
 ElseIf Me.Tipas = "SDM" Then
        Form_FrKodavimas.mp.Value = 5
 ElseIf Me.Tipas = "ISS" Then
        Form_FrKodavimas.mp.Value = 8
 ElseIf Me.Tipas = "EAS" Then
        Form_FrKodavimas.mp.Value = 9
 End If
 pEilid = Me.EilId
 pServer = Me.Server
End If
    'Form_FrSpecif.Navision_kodas.SetFocus

End Sub

此代码打开一个包含完成按钮的表单。单击完成按钮后,程序将执行另一个代码:

Private Sub CmbPabaiga_Click()
Dim PagamintasKiekisBefor As Long
If Me.CmbPabaiga.Value = True Then
            If (PatikrinamArNeraNuliniuPoziciju(Me)) = True Then
                        MsgBox " GA yra itrauktu poziciju kiriu kiekis lygus nuliui, arba mazesnis uz nuli" & Chr(13) & "Prasom istrinti sias pozicijas arba nurodyti ju kiekius" & Chr(13) & Chr(13) & "Prasom pasitikrinti ar nurodete Vietini Sandeli i kuri perkelti gamini", , "Rastos Nulines pozicijos GA"
                        Me.TxtbPabaigosData.Value = Null
                        Me.CmbPabaiga = False
                        Me.PagamintasKiekis.Locked = False
                        Exit Sub
            End If
            If Me.Tipas <> "Kiti" Then Me.PagamintasKiekis.Value = 1
                        PagamintasKiekisBefor = Me.PagamintasKiekis.Value
                        Me.Refresh
                        'SpecifikacijosAtnaujinimas Me, Me.GANr
                        VietinioSandelioAtzymejimas Me
                        Me.TxtbPabaigosData.Value = Now
                        Form_FrSpecif.Navision_kodas.Locked = True
                        Form_FrSpecif.Kiekis.Locked = True
                        Me.PagamintasKiekis.Locked = True

                            If Me.Tipas = "Kiti" Then KiekiuPeskPagalPagaminta Me, Me.CmbPabaiga.Value

                        Me.Refresh
                        PerskaiciuotiBendraKieki Me, PagamintasKiekisBefor
                        Me.Refresh
                        AtzymetiUZSKPabaiga Me, True
        Else
            If (TikrinamArJauNusiustasApskaitai(Me)) = False Then

                        PagamintasKiekisBefor = (Me.PagamintasKiekis.Value)
                        Me.Refresh
                        Me.TxtbPabaigosData.Value = Null
                        VietinioSandelioAtzymejimoPanaikinimas Me
                        Form_FrSpecif.Navision_kodas.Locked = False
                        Form_FrSpecif.Kiekis.Locked = False
                        Me.PagamintasKiekis.Locked = False
                        AtzymetiUZSKPabaiga Me, False

                            If Me.Tipas = "Kiti" Then KiekiuPeskPagalPagaminta Me, Me.CmbPabaiga.Value

                        PerskaiciuotiBendraKieki Me, 0 'PagamintasKiekisBefor
                        Me.PagamintasKiekis.Locked = False
                    Else

                        Me.CmbPabaiga = True
                        Form_FrSpecif.Navision_kodas.Locked = True
                        Form_FrSpecif.Kiekis.Locked = True
                        Me.PagamintasKiekis.Locked = True

            End If
End If
Me.TBSpecif.SetFocus

End Sub

因此,如果我在A列中有500条记录具有完全相同的值,我必须双击500次(等待加载),然后按完500次,并在中间做很多等待。

有没有办法可以在A列中具有给定值的所有条目上执行宏?

希望我已经很好地解释了这个问题

0 个答案:

没有答案