quietstormtw
Programmer
Hi all, I have finally reached my wits end...I need some major assistance.The code below is what I have been able to come up with so far, however, it is not taking me to my ultimate goal.
What I would like to do is:
1) Have the users enter the case number the they would like to add or modify
2) Use the case # entered to interogate the query to find is CaseNBR is present
3) If the CaseNBR is not present, return an error message
4) If the Case NBR is present, have the code also look at the CaseNo field, which should be equal to CaseNBR
5) If the Case # entered matches both, CaseNBR & CaseNo, the open the testCAR form in Edit mode
6) If the Case # entered matches the CaseNBR, but not the CaseNo, have the form open in ???? mode...and populate the CaseNo field with the number from CaseNBR
Private Sub Preview_Click()
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
strSQL = "Select qryMain.*" & _
"From qryMain"
strWhere = "Where"
strOrder = "Order BY qryMain.CaseNBR"
If Not IsNull(Me.txtCase) Then
strWhere = strWhere & " (qryMain.CaseNBR) = " & Me.txtCase & " AND "
End If
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
Set qryDef = dbNm.QueryDefs("qryDateRange")
qryDef.SQL = strSQL & " " & strWhere & " " & strOrder
Dim rsCnt As Variant
rsCnt = DCount("[CaseNBR]", "qryDateRange")
If rsCnt = 1 Then
DoCmd.OpenForm "testCar", acNormal
MsgBox "Form Add", vbOKOnly
If IsNull([Forms]![testCar]![CaseNo]) Then
Forms!testCar!CaseNo = Me.txtCase
End If
ElseIf rsCnt = 0 Then
MsgBox "There is no Case # for this request. Please ensure that an address is entered in Paragon", vbOKOnly, "No Data"
Exit Sub
ElseIf IsNull(Me.txtCase) Then
MsgBox "Please enter a Case # for this request", vbOKOnly, "No Case #"
End If
DoCmd.Close acForm, "frmtestCAR", acSaveYes
End Sub
Any advise is welcomed...and appreciated!!
What I would like to do is:
1) Have the users enter the case number the they would like to add or modify
2) Use the case # entered to interogate the query to find is CaseNBR is present
3) If the CaseNBR is not present, return an error message
4) If the Case NBR is present, have the code also look at the CaseNo field, which should be equal to CaseNBR
5) If the Case # entered matches both, CaseNBR & CaseNo, the open the testCAR form in Edit mode
6) If the Case # entered matches the CaseNBR, but not the CaseNo, have the form open in ???? mode...and populate the CaseNo field with the number from CaseNBR
Private Sub Preview_Click()
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
strSQL = "Select qryMain.*" & _
"From qryMain"
strWhere = "Where"
strOrder = "Order BY qryMain.CaseNBR"
If Not IsNull(Me.txtCase) Then
strWhere = strWhere & " (qryMain.CaseNBR) = " & Me.txtCase & " AND "
End If
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
Set qryDef = dbNm.QueryDefs("qryDateRange")
qryDef.SQL = strSQL & " " & strWhere & " " & strOrder
Dim rsCnt As Variant
rsCnt = DCount("[CaseNBR]", "qryDateRange")
If rsCnt = 1 Then
DoCmd.OpenForm "testCar", acNormal
MsgBox "Form Add", vbOKOnly
If IsNull([Forms]![testCar]![CaseNo]) Then
Forms!testCar!CaseNo = Me.txtCase
End If
ElseIf rsCnt = 0 Then
MsgBox "There is no Case # for this request. Please ensure that an address is entered in Paragon", vbOKOnly, "No Data"
Exit Sub
ElseIf IsNull(Me.txtCase) Then
MsgBox "Please enter a Case # for this request", vbOKOnly, "No Case #"
End If
DoCmd.Close acForm, "frmtestCAR", acSaveYes
End Sub
Any advise is welcomed...and appreciated!!