search for a character in a string

BadKitty

Registered User.
Local time
Today, 02:04
Joined
Jul 7, 2005
Messages
55
i know this is really simple, but i can't for the life of me remember how to do it!:mad:
so here's the sitch...
i've created a database for city permits to be issued. there are 4 types of permits (hydrant, meter, sewer, tap). in one of my forms, i have the user enter the type of permit (h, m, s, or t) and have the permit number set to autonumber. i created a query that concatenates the letter entered w/the autonumber assigned (ie - h12) and used that field (PermitNo) on another form which is to enter payment information. on this form i also have a button to print the current permit (open report). thing is, i have four seperate reports, each designed to look like whichever permit it is. i'd like to add the select case statement or an if else statement to the open report command so that if the current permit is h12 it will open the hydrant permit report. the code is pasted below. what else needs to be inside the quotes to accomplish this? also, please let me know if my syntax is correct.:o right now i have the cmd button set to preview...

Private Sub cmdPreviewPermit_Click()
On Error GoTo Err_cmdPreviewPermit_Click

Dim permitNo As String

If permitNo = "h" Then
DoCmd.OpenReport "rptHydrant", acPreview
ElseIf permitNo = "m" Then
DoCmd.OpenReport "rptMeter", acPreview
ElseIf permitNo = "s" Then
DoCmd.OpenReport "rptSewer", acPreiview
ElseIf permitNo = "t" Then
DoCmd.OpenReport "rptTap", acPreview
End If

Exit_cmdPreviewPermit_Click:
Exit Sub

Err_cmdPreviewPermit_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewPermit_Click

End Sub


thanx in advance!:)
 
If Left$(permitNo,1) = "?" then...

or

Select Case Left$(permitNo,1)
Case "h":
DoCmd.OpenReport
Case "m":
DoCmd.OpenReport
...
End Select

HTH
 
help

thanx for the quick response, but i'm not getting any results...the button isn't opening any reports when i click it. :confused: maybe i'm missing something. here's the code...

Private Sub cmdTestIfElse_Click()
On Error GoTo Err_cmdTestIfElse_Click

Dim permitNo As String

If Left$(permitNo, 1) = "h" Then
DoCmd.OpenReport "rptHydrant", acPreview
ElseIf Left$(permitNo, 1) = "m" Then
DoCmd.OpenReport "rptMeter", acPreview
ElseIf Left(permitNo, 1) = "s" Then
DoCmd.OpenReport "rptSewer", acPreiview
ElseIf Left$(permitNo, 1) = "t" Then
DoCmd.OpenReport "rptTap", acPreview
End If

Exit_cmdTestIfElse_Click:
Exit Sub

Err_cmdTestIfElse_Click:
MsgBox Err.Description
Resume Exit_cmdTestIfElse_Click

End Sub
 
You're not assigning anything to permitNo!
 
thanx!

oops...i tend to overlook the small stuff. :o it works fine now. thanx a bunch!
 
swap

that all works perfectly, but say now that i have the # preceding the letter...
does this require a great deal of modification to my existin code?
 
If the letter is at the end, all you'd need to do is change Left to Right.
 
that's what i figured...just wanted to make sure. thanx!;)
 

Users who are viewing this thread

Back
Top Bottom