G
Guest
I am trying to construct a macro with a condition. I have a query that
counts the number of records based on a criteria. The query does the count
correctly but how do I set the condition correctly. I have tried this in vba
and using the interface and can't seem to get it to work. Here is the vba
code:
Private Sub CmdOK_Click()
Dim DB As Database
Set DB = CurrentDb
Dim rec As DAO.Recordset
With CodeContextObject
.Visible = True
DoCmd.SetWarnings False
' Count if Work ID number already exists in table
DoCmd.OpenQuery "qryCountIDTR", acViewNormal, acEdit
Set rec = DB.OpenRecordset("tblCountWR")
If CountOfWorkReqID > "0" Then
' Open form to select if WR is rework
DoCmd.OpenForm "qryWRExist", acNormal, "", "", , acNormal
DoCmd.SetWarnings True
End If
' Append Data from Quality Checklist
DoCmd.OpenQuery "qryappendTR", acViewNormal, acEdit
' Update table with Work Request (Check ID), date, Checklist type,
etc. - Product
DoCmd.OpenQuery "qryUpdateTR", acViewNormal, acEdit
' Create Record for Tracking Time Spent
DoCmd.OpenQuery "qrycreateTimeTR", acViewNormal, acEdit
' Open form with fields to be updated/edited
DoCmd.OpenForm "frmInitialTR", acNormal, "", "", , acNormal
DoCmd.SetWarnings True
DoCmd.CancelEvent
End With
If IsNull(Me.[TxtWorkReq]) Then
MsgBox "Work Request Field Has No Data!!"
DoCmd.GoToControl "TxtDate"
Me![TxtWorkReq].SetFocus
End If
Me.[TxtWorkReq].SetFocus
Me![CmdOK].Visible = False
Me![CmdCancel].Visible = False
Me![PauseReturn].Visible = True
End Sub
Private Sub TxtWorkReq_AfterUpdate()
DoCmd.OpenQuery "qryStartTR"
End Sub
Private Sub TxtWorkReq_Change()
If IsNull(Me.[TxtWorkReq]) Then
MsgBox "Work Request Field Has No Data!!"
DoCmd.GoToControl "TxtDate"
Me![TxtWorkReq].SetFocus
Exit Sub
End If
End Sub
The query is a make table query and it makes the table correctly. Then I
open the table and determine if the field is greater than 0. If so, it
should open a form that gives options and stops at that point. The field
shows greater than 0 but the code keeps running and does not pull up the form
and stop the rest of the code.
Any help would be appreciated.
counts the number of records based on a criteria. The query does the count
correctly but how do I set the condition correctly. I have tried this in vba
and using the interface and can't seem to get it to work. Here is the vba
code:
Private Sub CmdOK_Click()
Dim DB As Database
Set DB = CurrentDb
Dim rec As DAO.Recordset
With CodeContextObject
.Visible = True
DoCmd.SetWarnings False
' Count if Work ID number already exists in table
DoCmd.OpenQuery "qryCountIDTR", acViewNormal, acEdit
Set rec = DB.OpenRecordset("tblCountWR")
If CountOfWorkReqID > "0" Then
' Open form to select if WR is rework
DoCmd.OpenForm "qryWRExist", acNormal, "", "", , acNormal
DoCmd.SetWarnings True
End If
' Append Data from Quality Checklist
DoCmd.OpenQuery "qryappendTR", acViewNormal, acEdit
' Update table with Work Request (Check ID), date, Checklist type,
etc. - Product
DoCmd.OpenQuery "qryUpdateTR", acViewNormal, acEdit
' Create Record for Tracking Time Spent
DoCmd.OpenQuery "qrycreateTimeTR", acViewNormal, acEdit
' Open form with fields to be updated/edited
DoCmd.OpenForm "frmInitialTR", acNormal, "", "", , acNormal
DoCmd.SetWarnings True
DoCmd.CancelEvent
End With
If IsNull(Me.[TxtWorkReq]) Then
MsgBox "Work Request Field Has No Data!!"
DoCmd.GoToControl "TxtDate"
Me![TxtWorkReq].SetFocus
End If
Me.[TxtWorkReq].SetFocus
Me![CmdOK].Visible = False
Me![CmdCancel].Visible = False
Me![PauseReturn].Visible = True
End Sub
Private Sub TxtWorkReq_AfterUpdate()
DoCmd.OpenQuery "qryStartTR"
End Sub
Private Sub TxtWorkReq_Change()
If IsNull(Me.[TxtWorkReq]) Then
MsgBox "Work Request Field Has No Data!!"
DoCmd.GoToControl "TxtDate"
Me![TxtWorkReq].SetFocus
Exit Sub
End If
End Sub
The query is a make table query and it makes the table correctly. Then I
open the table and determine if the field is greater than 0. If so, it
should open a form that gives options and stops at that point. The field
shows greater than 0 but the code keeps running and does not pull up the form
and stop the rest of the code.
Any help would be appreciated.