Case Select when StLinkCriteria is Null??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

Can I use a case select for the following form code? Any help will be most
appreciated, I've tried it but so far have failed. I prefer to not have the
Debug option show up if a search criteria is entered incorrectly.


Private Sub Form_Timer()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmVMP5"

stLinkCriteria = "[tblVMP].[VMPHiddenNumber]=" & Me![VMPHiddenNumber]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "frmFindVMPByReportNumber", acSaveYes
End Sub


What I want is if stLinkCriteria returns an error for form "frmVMP3" to open.

Again any help is most appreciated.
Mary
 
Private Sub Form_Timer()
Dim stDocName3 As String
Dim stDocName5 As String
Dim stLinkCriteria As Variant

stDocName3 = "frmVMP3"
stDocName5 = "frmVMP5"
If IsNull(DLookdup("[VMPHiddenNumber]", "tblVMP", _ &
"[VMPHiddenNumber] = " & Me![VMPHiddenNumber])) Then
DoCmd.OpenForm stDocName3
Else
stLinkCriteria = "[tblVMP].[VMPHiddenNumber]=" & Me![VMPHiddenNumber]
DoCmd.OpenForm stDocName5, , , stLinkCriteria
End If
DoCmd.Close acForm, "frmFindVMPByReportNumber", acSaveYes
End Sub
 
Hi.

Try:

Private Sub Form_Timer()

On Error GoTo ErrHandler

Dim stDocName As String
Dim sAlternate As String
Dim stLinkCriteria As String

stDocName = "frmVMP5"
sAlternate = "frmVMP3"
stLinkCriteria = "[tblVMP].[VMPHiddenNumber]=" & Me![VMPHiddenNumber]

If (Nz(stLinkCriteria, "") = "") Then
DoCmd.OpenForm sAlternate
ElseIf (IsNumeric(stLinkCriteria)) Then
DoCmd.OpenForm strDocName, , , stLinkCriteria
Else
DoCmd.OpenForm sAlternate
End If

DoCmd.Close acForm, "frmFindVMPByReportNumber", acSaveYes

Exit Sub

ErrHandler:

MsgBox "Error in Form_Timer( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Private Sub Form_Timer()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmVMP5"

stLinkCriteria = "[tblVMP].[VMPHiddenNumber]=" & Me![VMPHiddenNumber]
If IsNull(DLookup("VMPHiddenNumber", "tblVMP", _
"[VMPHiddenNumber]=" & Me![VMPHiddenNumber]) Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
DoCmd.OpenForm "frmVMP3"
End If
'
'--- Did you know that the 'acSaveYes' at the end of the following DoCmd line
'--- saves any changes to the *form*...but NOT the data?

DoCmd.Close acForm, "frmFindVMPByReportNumber", acSaveYes
End Sub


Hi all,

Can I use a case select for the following form code? Any help will be most
appreciated, I've tried it but so far have failed. I prefer to not have the
Debug option show up if a search criteria is entered incorrectly.


Private Sub Form_Timer()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmVMP5"

stLinkCriteria = "[tblVMP].[VMPHiddenNumber]=" & Me![VMPHiddenNumber]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "frmFindVMPByReportNumber", acSaveYes
End Sub


What I want is if stLinkCriteria returns an error for form "frmVMP3" to open.

Again any help is most appreciated.
Mary

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
Klatuu got it right and my logic is backwards. :(

Hi all,

Can I use a case select for the following form code? Any help will be most
appreciated, I've tried it but so far have failed. I prefer to not have the
Debug option show up if a search criteria is entered incorrectly.


Private Sub Form_Timer()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmVMP5"

stLinkCriteria = "[tblVMP].[VMPHiddenNumber]=" & Me![VMPHiddenNumber]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "frmFindVMPByReportNumber", acSaveYes
End Sub


What I want is if stLinkCriteria returns an error for form "frmVMP3" to open.

Again any help is most appreciated.
Mary

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
LOL :)

Thats the way to job security!!!
Write more code to get the same error!!!



RuralGuy said:
Klatuu got it right and my logic is backwards. :(

Hi all,

Can I use a case select for the following form code? Any help will be most
appreciated, I've tried it but so far have failed. I prefer to not have the
Debug option show up if a search criteria is entered incorrectly.


Private Sub Form_Timer()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmVMP5"

stLinkCriteria = "[tblVMP].[VMPHiddenNumber]=" & Me![VMPHiddenNumber]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "frmFindVMPByReportNumber", acSaveYes
End Sub


What I want is if stLinkCriteria returns an error for form "frmVMP3" to open.

Again any help is most appreciated.
Mary

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
FerryMary said:
Can I use a case select for the following form code? Any help will be most
appreciated, I've tried it but so far have failed. I prefer to not have the
Debug option show up if a search criteria is entered incorrectly.


Private Sub Form_Timer()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmVMP5"

stLinkCriteria = "[tblVMP].[VMPHiddenNumber]=" & Me![VMPHiddenNumber]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "frmFindVMPByReportNumber", acSaveYes
End Sub

What I want is if stLinkCriteria returns an error for form "frmVMP3" to open.


What kind of error are you worried about?

If the user doesn't enter anything, what should happen?

Does VMPHiddenNumber have to be a number?

You can deal with these situations by using:
If IsNull(Me![VMPHiddenNumber]) _
OR Me![VMPHiddenNumber] Like "*[!0-9]*" Then
DoCmd.OpenForm "frmVMP3"
Else
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
 
Marshall Barton said:
What kind of error are you worried about?

If user enters a report number that does not exist the stLinkCriteria has no
means to locate the record, so an error message was popping to that effect,
with an option to Debug.
If the user doesn't enter anything, what should happen?

Does VMPHiddenNumber have to be a number?

You can deal with these situations by using:
If IsNull(Me![VMPHiddenNumber]) _
OR Me![VMPHiddenNumber] Like "*[!0-9]*" Then
DoCmd.OpenForm "frmVMP3"
Else
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

I have seen many posts regarding parameter queries and how they can be good
in some cases, but not so good in other cases. I was using a parameter
query as the basis of this form which locates maintenance records. After
reading all the posts again and trying out various codes I changed the query
(eliminated the [Enter Report Number:]) and just added a combo box so if user
enters number wrong now it is apparent prior to attempting to open correct
form. Originally the user did not see this form, other than the [Enter
Report Number:] portion of it.

Thanks so much for your time.
Mary
 

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

Back
Top