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

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!
 
D

Douglas J. Steele

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
 
P

Peter

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!
 
K

Keith Wilby

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
 
P

Peter

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top