I am not "getting" it.....DoCmd. OpenForm

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hi all…sorry for bothering you all time, but I am not “getting†it..

Below code returns Error highlighted DoCmd.OpenForm stDocName, , ,
stLinkCriteria and the MsgBox does not “fire†if [CaseID] is left empty…

Private Sub OpenSingleViewFromBagMenu_Click()
On Error GoTo Err_OpenSingleViewFromBagMenu_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Single View"

stLinkCriteria = "[Case ID]=" & Me![CaseID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

If Not IsNull(Me.CaseID) Then
stLinkCriteria = "[Case ID]=" & Me![Case ID]
MsgBox “You left the Search fieled empty!
End If


Exit_OpenSingleViewFromFBMenu_Click:
Exit Sub

Err_OpenSingleViewFromFBMenu_Click:
MsgBox Err.Description
Resume Exit_OpenSingleViewFromFBMenu_Click

End Sub

Thanks!
 
You should be checking whether the field's been populated before you try to
open the form (and your check is backwards: you've got a problem when Case
ID is Null, not when it's Not Null!)


Private Sub OpenSingleViewFromBagMenu_Click()
On Error GoTo Err_OpenSingleViewFromBagMenu_Click

Dim stDocName As String
Dim stLinkCriteria As String


If IsNull(Me.CaseID) Then
MsgBox "You left the Search field empty!"
Else
stDocName = "Single View"
stLinkCriteria = "[Case ID]=" & Me![CaseID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Exit_OpenSingleViewFromFBMenu_Click:
Exit Sub

Err_OpenSingleViewFromFBMenu_Click:
MsgBox Err.Description
Resume Exit_OpenSingleViewFromFBMenu_Click

End Sub


Be aware that sometimes a text box can be blank, as opposed to Null. To
handle that case, I'd recommend using

If Len(Me.CaseID & vbNullString) = 0 Then

or even

If Len(Trim(Me.CaseID & vbNullString)) = 0 Then

rather than

If IsNull(Me.CaseID) Then
 
Indeed very helpful Douglas...indeed...logics...OK. I will try this. Once
again, thanks for your patiance!

Douglas J. Steele said:
You should be checking whether the field's been populated before you try to
open the form (and your check is backwards: you've got a problem when Case
ID is Null, not when it's Not Null!)


Private Sub OpenSingleViewFromBagMenu_Click()
On Error GoTo Err_OpenSingleViewFromBagMenu_Click

Dim stDocName As String
Dim stLinkCriteria As String


If IsNull(Me.CaseID) Then
MsgBox "You left the Search field empty!"
Else
stDocName = "Single View"
stLinkCriteria = "[Case ID]=" & Me![CaseID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Exit_OpenSingleViewFromFBMenu_Click:
Exit Sub

Err_OpenSingleViewFromFBMenu_Click:
MsgBox Err.Description
Resume Exit_OpenSingleViewFromFBMenu_Click

End Sub


Be aware that sometimes a text box can be blank, as opposed to Null. To
handle that case, I'd recommend using

If Len(Me.CaseID & vbNullString) = 0 Then

or even

If Len(Trim(Me.CaseID & vbNullString)) = 0 Then

rather than

If IsNull(Me.CaseID) Then


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Peter said:
Hi all.sorry for bothering you all time, but I am not "getting" it..

Below code returns Error highlighted DoCmd.OpenForm stDocName, , ,
stLinkCriteria and the MsgBox does not "fire" if [CaseID] is left empty.

Private Sub OpenSingleViewFromBagMenu_Click()
On Error GoTo Err_OpenSingleViewFromBagMenu_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Single View"

stLinkCriteria = "[Case ID]=" & Me![CaseID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

If Not IsNull(Me.CaseID) Then
stLinkCriteria = "[Case ID]=" & Me![Case ID]
MsgBox "You left the Search fieled empty!
End If


Exit_OpenSingleViewFromFBMenu_Click:
Exit Sub

Err_OpenSingleViewFromFBMenu_Click:
MsgBox Err.Description
Resume Exit_OpenSingleViewFromFBMenu_Click

End Sub

Thanks!
 
Peter said:
Hi all…sorry for bothering you all time, but I am not “getting†it..

Below code returns Error highlighted DoCmd.OpenForm stDocName, , ,
stLinkCriteria and the MsgBox does not “fire†if [CaseID] is left empty…

What's the error message? Is the content of CaseID numeric?

Keith.
www.keithwilby.co.uk
 
ITS CHRISTMAS.IT WORKS GREAT.

THANKS MR Douglas!!!

Douglas J. Steele said:
You should be checking whether the field's been populated before you try to
open the form (and your check is backwards: you've got a problem when Case
ID is Null, not when it's Not Null!)


Private Sub OpenSingleViewFromBagMenu_Click()
On Error GoTo Err_OpenSingleViewFromBagMenu_Click

Dim stDocName As String
Dim stLinkCriteria As String


If IsNull(Me.CaseID) Then
MsgBox "You left the Search field empty!"
Else
stDocName = "Single View"
stLinkCriteria = "[Case ID]=" & Me![CaseID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Exit_OpenSingleViewFromFBMenu_Click:
Exit Sub

Err_OpenSingleViewFromFBMenu_Click:
MsgBox Err.Description
Resume Exit_OpenSingleViewFromFBMenu_Click

End Sub


Be aware that sometimes a text box can be blank, as opposed to Null. To
handle that case, I'd recommend using

If Len(Me.CaseID & vbNullString) = 0 Then

or even

If Len(Trim(Me.CaseID & vbNullString)) = 0 Then

rather than

If IsNull(Me.CaseID) Then


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Peter said:
Hi all.sorry for bothering you all time, but I am not "getting" it..

Below code returns Error highlighted DoCmd.OpenForm stDocName, , ,
stLinkCriteria and the MsgBox does not "fire" if [CaseID] is left empty.

Private Sub OpenSingleViewFromBagMenu_Click()
On Error GoTo Err_OpenSingleViewFromBagMenu_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Single View"

stLinkCriteria = "[Case ID]=" & Me![CaseID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

If Not IsNull(Me.CaseID) Then
stLinkCriteria = "[Case ID]=" & Me![Case ID]
MsgBox "You left the Search fieled empty!
End If


Exit_OpenSingleViewFromFBMenu_Click:
Exit Sub

Err_OpenSingleViewFromFBMenu_Click:
MsgBox Err.Description
Resume Exit_OpenSingleViewFromFBMenu_Click

End Sub

Thanks!
 
Back
Top