I have two test records in my database for development purposes. The two
projects numbers are "Test-0001" which is the format of the actual project
numbers (????99-0000) and "12345". When I run the code, if I type either of
these or "0001" I get a NoMatch. Why does the module not find the record?
Does it matter that my on load, my form goes to a new record?
Code:
Public Sub ExportEstimate()
'On Error GoTo Err_Export
Dim Dsktp, Tmplt, Msg, Proj As String, CurUser As Object, Warn As Integer
DoCmd.OpenForm "GenerateEstimate", acNormal ', , , , acHidden
Proj = InputBox("Enter Project Number")
If Not IsNull(Proj) Then
If Len(Proj) = 4 Then
With Forms![GeneratEestimate].RecordsetClone
.FindFirst "Right([ProjNo],4) =" & """ & Proj & """
If .NoMatch Then
MsgBox "No Project Found"
Else
Forms![GeneratEestimate].Bookmark = .Bookmark
End If
End With
Else
With Forms![GeneratEestimate].RecordsetClone
.FindFirst "[ProjNo] =" & """ & Proj & """
If .NoMatch Then
MsgBox "No Project Found"
Else
Forms![GeneratEestimate].Bookmark = .Bookmark
End If
End With
End If
'Run Query and Export Code Here, uses Dsktp, Tmplt, Msg, CurUser, Warn
End If
Exit_Export:
Exit Sub
'Err_Export:
'MsgBox Err.Description
'Resume Exit_Export
End Sub
I replced
.FindFirst "Right([ProjNo],4) =" & """ & Proj & """
with
.FindFirst "Right([ProjNo],4) =" & Chr(34) & Proj & Chr(34)
AND
.FindFirst "[ProjNo] =" & """ & Proj & """
with
.FindFirst "[ProjNo] =" & Chr(34) & Proj & Chr(34)
That is certainly a valid way to do that so no need to make
any other changes.
Your original problem was that you did not have the correct
number of quotes. The basic rule of putting a quote inside
quotes is to use two quotes where you want one quote in the
result.
Note that Chr(34) is the same as """" so you could have
solved the problem by using:
.FindFirst "[ProjNo] =" & """" & Proj & """"
You could also have combined the first set of quotes into
the initial part of the expression:
.FindFirst "[ProjNo] =""" & Proj & """"
--
Marsh
MVP [MS Access]