VBA coding hlp plse

J

Junior

I have this code in clik event of a form
If not .EOF then the form opens but the program keeps running
how can i change my code to open the form and stop any further action until
the form is closed


Dim rst As dao.Recordset
Dim sxSQL As String, strErr As String
strErr = "OK"
sxSQL = "SELECT TOP 1 SOC FROM QFindCstOrgErr "
Set rst = CurrentDb.OpenRecordset(sxSQL)
With rst

DoCmd.SetWarnings False

If Not .EOF Then

DoCmd.OpenForm "frmCstOrgErr", acNormal, "", "", acEdit, acNormal

Else: MsgBox "No CstOrg errors were found - press ok to continue"
End If
Set rst = Nothing

more code.......

End With
 
D

Dirk Goldgar

Junior said:
I have this code in clik event of a form
If not .EOF then the form opens but the program keeps running
how can i change my code to open the form and stop any further action
until the form is closed


Dim rst As dao.Recordset
Dim sxSQL As String, strErr As String
strErr = "OK"
sxSQL = "SELECT TOP 1 SOC FROM QFindCstOrgErr "
Set rst = CurrentDb.OpenRecordset(sxSQL)
With rst

DoCmd.SetWarnings False

If Not .EOF Then

DoCmd.OpenForm "frmCstOrgErr", acNormal, "", "", acEdit,
acNormal

Else: MsgBox "No CstOrg errors were found - press ok to continue"
End If
Set rst = Nothing

more code.......

End With

DoCmd.OpenForm "frmCstOrgErr", _
DataMode:=acFormEdit,
WindowMode:=acDialog
 
R

Ronald Dodge

Note the "Else" part of the code here and the ending part of the code.

Dim rst As dao.Recordset
Dim sxSQL As String, strErr As String
On Error Goto ErrHandle
strErr = "OK"
sxSQL = "SELECT TOP 1 SOC FROM QFindCstOrgErr "
Set rst = CurrentDb.OpenRecordset(sxSQL)
With rst

DoCmd.SetWarnings False

If Not .EOF Then
DoCmd.OpenForm "frmCstOrgErr", acNormal, "", "", acEdit, acNormal
Else
MsgBox "No CstOrg errors were found - press ok to continue"
Set rst = Nothing
End With
Goto ExitSub
End If
Set rst = Nothing

more code.......

End With

ExitSub:
Exit Sub
ErrHandle:
<Code to handle the error, if any>
Resume ExitSub
End Sub
 
Top