I've tried mutiple things but no go -- (sorry this is so long)
I'm collecting a 5 digit number in an input box function and all works
fine until a number is passed that doesn't exist in the database. I
can't figure out where/how to check that the number exists before I
get the error code 2105. Here's my function to get the number that I
run when a command button is clicked to open the frmEditLoans form:
Public Function GoToLoanWithInp ut()
Dim Msg, Title, Defvalue, Answer, Cancel
Msg = "Enter VIN # last five digits" _
& vbCrLf & vbCrLf & "Quick Tip: if you do not know Vin #," _
& vbCrLf & " Copy and Paste from the ""Last 5 digits of Vin #""" _
& vbCrLf & "field on the Edit menu's View Loan/Find Loan form."
Title = "Open Edit Loan Form"
Defvalue = "00000"
Answer = InputBox(Msg, Title, Defvalue)
If Answer = "00000" Then
MsgBox ("You need to enter a valid VIN ID #")
Call GoToLoanWithInp ut
Exit Function
End If
If Answer = "" Then
If IsLoaded("frmEd itLoans") Then
DoCmd.Close acForm, "frmEditLoa ns"
End If
DoCmd.OpenForm "Switchboar d"
End If
If Answer <> "" Then
DoCmd.OpenForm "frmEditLoa ns", , , "Right([VehicleVin],5)='" &
Answer & "' "
Exit Function
End If
End Function
Here's my unrelated conditional code that kicks in On Open event of
frmEditLoans:
Private Sub Form_Open(Cance l As Integer)
If IsDate(Me.Last_ Statement) Then
LoanOrigDate.En abled = False
Else
Me.LoanOrigDate .Enabled = True
(!**! debug highlights this:) Me.LoanOrigDate .SetFocus
If Me.CurtailmentR eq.Value = "No" Then
Me.CurtailmentP aymentAmount.Vi sible = False
Me.FirstPayDueD ate.Visible = False
Else: Me.CurtailmentP aymentAmount.Vi sible = True
Me.FirstPayDueD ate.Visible = True
End If
End If
End Sub
If the VIN # doesn't exist, the runTime error 2105 "You can't go to
specified record." appears. Clicking debug highlights at the !**!
above. Putting the error in a Sub Form_Error event doesn't seem to
work unless I'm not contructing it correctly--which is possible.
I've learned so much from reading your answers to other people's
problems. Hope you can help me now.
Sharon 8 5154
Thanks so much, TC. I'll give this a shot - I'm assuming I'll work
this in when the Answer <> "" Then ...right before telling the form to
open the next form?
Sharonky
"TC" <a@b.c.d> wrote in message news:<106947573 1.952084@teutho s>... If you want to check whether there is a record in table XXX where the value of field FFF is 999:
if nz (dlookup(true, "XXX", "FFF=999"), false) then ' it DOES eist. else ' it DOES NOT exist. endif
Use your own values for XXX, FFF and 999.
HTH, TC
"swathky" <sw*****@integr anetics.com> wrote in message news:2b******** *************** **@posting.goog le.com... I've tried mutiple things but no go -- (sorry this is so long) I'm collecting a 5 digit number in an input box function and all works fine until a number is passed that doesn't exist in the database. I can't figure out where/how to check that the number exists before I get the error code 2105. Here's my function to get the number that I run when a command button is clicked to open the frmEditLoans form:
Public Function GoToLoanWithInp ut() Dim Msg, Title, Defvalue, Answer, Cancel
Msg = "Enter VIN # last five digits" _ & vbCrLf & vbCrLf & "Quick Tip: if you do not know Vin #," _ & vbCrLf & " Copy and Paste from the ""Last 5 digits of Vin #""" _ & vbCrLf & "field on the Edit menu's View Loan/Find Loan form."
Title = "Open Edit Loan Form"
Defvalue = "00000"
Answer = InputBox(Msg, Title, Defvalue)
If Answer = "00000" Then MsgBox ("You need to enter a valid VIN ID #") Call GoToLoanWithInp ut Exit Function End If
If Answer = "" Then If IsLoaded("frmEd itLoans") Then DoCmd.Close acForm, "frmEditLoa ns" End If DoCmd.OpenForm "Switchboar d" End If
If Answer <> "" Then DoCmd.OpenForm "frmEditLoa ns", , , "Right([VehicleVin],5)='" & Answer & "' " Exit Function End If
End Function
Here's my unrelated conditional code that kicks in On Open event of frmEditLoans:
Private Sub Form_Open(Cance l As Integer)
If IsDate(Me.Last_ Statement) Then LoanOrigDate.En abled = False Else Me.LoanOrigDate .Enabled = True (!**! debug highlights this:) Me.LoanOrigDate .SetFocus If Me.CurtailmentR eq.Value = "No" Then Me.CurtailmentP aymentAmount.Vi sible = False Me.FirstPayDueD ate.Visible = False Else: Me.CurtailmentP aymentAmount.Vi sible = True Me.FirstPayDueD ate.Visible = True End If End If End Sub
If the VIN # doesn't exist, the runTime error 2105 "You can't go to specified record." appears. Clicking debug highlights at the !**! above. Putting the error in a Sub Form_Error event doesn't seem to work unless I'm not contructing it correctly--which is possible. I've learned so much from reading your answers to other people's problems. Hope you can help me now. Sharon
If you want to check whether there is a record in table XXX where the value
of field FFF is 999:
if nz (dlookup(true, "XXX", "FFF=999"), false) then
' it DOES eist.
else
' it DOES NOT exist.
endif
Use your own values for XXX, FFF and 999.
HTH,
TC
"swathky" <sw*****@integr anetics.com> wrote in message
news:2b******** *************** **@posting.goog le.com... I've tried mutiple things but no go -- (sorry this is so long) I'm collecting a 5 digit number in an input box function and all works fine until a number is passed that doesn't exist in the database. I can't figure out where/how to check that the number exists before I get the error code 2105. Here's my function to get the number that I run when a command button is clicked to open the frmEditLoans form:
Public Function GoToLoanWithInp ut() Dim Msg, Title, Defvalue, Answer, Cancel
Msg = "Enter VIN # last five digits" _ & vbCrLf & vbCrLf & "Quick Tip: if you do not know Vin #," _ & vbCrLf & " Copy and Paste from the ""Last 5 digits of Vin #""" _ & vbCrLf & "field on the Edit menu's View Loan/Find Loan form."
Title = "Open Edit Loan Form"
Defvalue = "00000"
Answer = InputBox(Msg, Title, Defvalue)
If Answer = "00000" Then MsgBox ("You need to enter a valid VIN ID #") Call GoToLoanWithInp ut Exit Function End If
If Answer = "" Then If IsLoaded("frmEd itLoans") Then DoCmd.Close acForm, "frmEditLoa ns" End If DoCmd.OpenForm "Switchboar d" End If
If Answer <> "" Then DoCmd.OpenForm "frmEditLoa ns", , , "Right([VehicleVin],5)='" & Answer & "' " Exit Function End If
End Function
Here's my unrelated conditional code that kicks in On Open event of frmEditLoans:
Private Sub Form_Open(Cance l As Integer)
If IsDate(Me.Last_ Statement) Then LoanOrigDate.En abled = False Else Me.LoanOrigDate .Enabled = True (!**! debug highlights this:) Me.LoanOrigDate .SetFocus If Me.CurtailmentR eq.Value = "No" Then Me.CurtailmentP aymentAmount.Vi sible = False Me.FirstPayDueD ate.Visible = False Else: Me.CurtailmentP aymentAmount.Vi sible = True Me.FirstPayDueD ate.Visible = True End If End If End Sub
If the VIN # doesn't exist, the runTime error 2105 "You can't go to specified record." appears. Clicking debug highlights at the !**! above. Putting the error in a Sub Form_Error event doesn't seem to work unless I'm not contructing it correctly--which is possible. I've learned so much from reading your answers to other people's problems. Hope you can help me now. Sharon
Or, perhaps if you added some error handling code to field the
no-record-found-condition, you wouldn't need to check beforehand.
I don't see any error handling code in what you quoted. If you don't handle
the errors, Access does, in the not-too-friendly way you describe.
You really ought to have some error handling, anyway, because a missing
record isn't the only kind of error that could happen on the operation.
Larry Linson
Microsoft Access MVP
"swathky" <sw*****@integr anetics.com> wrote in message
news:2b******** *************** ***@posting.goo gle.com... Thanks so much, TC. I'll give this a shot - I'm assuming I'll work this in when the Answer <> "" Then ...right before telling the form to open the next form? Sharonky "TC" <a@b.c.d> wrote in message news:<106947573 1.952084@teutho s>... If you want to check whether there is a record in table XXX where the
value of field FFF is 999:
if nz (dlookup(true, "XXX", "FFF=999"), false) then ' it DOES eist. else ' it DOES NOT exist. endif
Use your own values for XXX, FFF and 999.
HTH, TC
"swathky" <sw*****@integr anetics.com> wrote in message news:2b******** *************** **@posting.goog le.com... I've tried mutiple things but no go -- (sorry this is so long) I'm collecting a 5 digit number in an input box function and all works fine until a number is passed that doesn't exist in the database. I can't figure out where/how to check that the number exists before I get the error code 2105. Here's my function to get the number that I run when a command button is clicked to open the frmEditLoans form:
Public Function GoToLoanWithInp ut() Dim Msg, Title, Defvalue, Answer, Cancel
Msg = "Enter VIN # last five digits" _ & vbCrLf & vbCrLf & "Quick Tip: if you do not know Vin #," _ & vbCrLf & " Copy and Paste from the ""Last 5 digits of Vin #""" _ & vbCrLf & "field on the Edit menu's View Loan/Find Loan form."
Title = "Open Edit Loan Form"
Defvalue = "00000"
Answer = InputBox(Msg, Title, Defvalue)
If Answer = "00000" Then MsgBox ("You need to enter a valid VIN ID #") Call GoToLoanWithInp ut Exit Function End If
If Answer = "" Then If IsLoaded("frmEd itLoans") Then DoCmd.Close acForm, "frmEditLoa ns" End If DoCmd.OpenForm "Switchboar d" End If
If Answer <> "" Then DoCmd.OpenForm "frmEditLoa ns", , , "Right([VehicleVin],5)='" & Answer & "' " Exit Function End If
End Function
Here's my unrelated conditional code that kicks in On Open event of frmEditLoans:
Private Sub Form_Open(Cance l As Integer)
If IsDate(Me.Last_ Statement) Then LoanOrigDate.En abled = False Else Me.LoanOrigDate .Enabled = True (!**! debug highlights this:) Me.LoanOrigDate .SetFocus If Me.CurtailmentR eq.Value = "No" Then Me.CurtailmentP aymentAmount.Vi sible = False Me.FirstPayDueD ate.Visible = False Else: Me.CurtailmentP aymentAmount.Vi sible = True Me.FirstPayDueD ate.Visible = True End If End If End Sub
If the VIN # doesn't exist, the runTime error 2105 "You can't go to specified record." appears. Clicking debug highlights at the !**! above. Putting the error in a Sub Form_Error event doesn't seem to work unless I'm not contructing it correctly--which is possible. I've learned so much from reading your answers to other people's problems. Hope you can help me now. Sharon
Sure, you would put the OpenForm (to open the next form) in the "true" part
of the if-test, for example:
if nz (dlookup(true, "XXX", "FFF=999"), false) then
' it DOES exist.
docmd.openform ...
else
msg "That number is not on file"
endif
HTH,
TC
"swathky" <sw*****@integr anetics.com> wrote in message
news:2b******** *************** ***@posting.goo gle.com... Thanks so much, TC. I'll give this a shot - I'm assuming I'll work this in when the Answer <> "" Then ...right before telling the form to open the next form? Sharonky "TC" <a@b.c.d> wrote in message news:<106947573 1.952084@teutho s>... If you want to check whether there is a record in table XXX where the
value of field FFF is 999:
if nz (dlookup(true, "XXX", "FFF=999"), false) then ' it DOES eist. else ' it DOES NOT exist. endif
Use your own values for XXX, FFF and 999.
HTH, TC
"swathky" <sw*****@integr anetics.com> wrote in message news:2b******** *************** **@posting.goog le.com... I've tried mutiple things but no go -- (sorry this is so long) I'm collecting a 5 digit number in an input box function and all works fine until a number is passed that doesn't exist in the database. I can't figure out where/how to check that the number exists before I get the error code 2105. Here's my function to get the number that I run when a command button is clicked to open the frmEditLoans form:
Public Function GoToLoanWithInp ut() Dim Msg, Title, Defvalue, Answer, Cancel
Msg = "Enter VIN # last five digits" _ & vbCrLf & vbCrLf & "Quick Tip: if you do not know Vin #," _ & vbCrLf & " Copy and Paste from the ""Last 5 digits of Vin #""" _ & vbCrLf & "field on the Edit menu's View Loan/Find Loan form."
Title = "Open Edit Loan Form"
Defvalue = "00000"
Answer = InputBox(Msg, Title, Defvalue)
If Answer = "00000" Then MsgBox ("You need to enter a valid VIN ID #") Call GoToLoanWithInp ut Exit Function End If
If Answer = "" Then If IsLoaded("frmEd itLoans") Then DoCmd.Close acForm, "frmEditLoa ns" End If DoCmd.OpenForm "Switchboar d" End If
If Answer <> "" Then DoCmd.OpenForm "frmEditLoa ns", , , "Right([VehicleVin],5)='" & Answer & "' " Exit Function End If
End Function
Here's my unrelated conditional code that kicks in On Open event of frmEditLoans:
Private Sub Form_Open(Cance l As Integer)
If IsDate(Me.Last_ Statement) Then LoanOrigDate.En abled = False Else Me.LoanOrigDate .Enabled = True (!**! debug highlights this:) Me.LoanOrigDate .SetFocus If Me.CurtailmentR eq.Value = "No" Then Me.CurtailmentP aymentAmount.Vi sible = False Me.FirstPayDueD ate.Visible = False Else: Me.CurtailmentP aymentAmount.Vi sible = True Me.FirstPayDueD ate.Visible = True End If End If End Sub
If the VIN # doesn't exist, the runTime error 2105 "You can't go to specified record." appears. Clicking debug highlights at the !**! above. Putting the error in a Sub Form_Error event doesn't seem to work unless I'm not contructing it correctly--which is possible. I've learned so much from reading your answers to other people's problems. Hope you can help me now. Sharon
Yes! this works. Point well taken, Larry, I tried several error
handling lines that didn't work before I wrote in, and, since I
couldn't get them to do what I wanted, I apparently still have a great
deal to learn there. Thanks again, TC!
'check to see if valid VIN #
If DLookup("[Last5]", "qryValVinCurre nt", "[Last5] ='" & Answer
& "' ") Then
DoCmd.OpenForm "frmEditLoa ns", , , "Right([VehicleVin],5)='" &
Answer & "' "
Else
'VIN# doesn't exist
MsgBox ("The VIN # you entered is not valid." & Chr(13) &
"Please verify # and try again.")
Call GoToLoanWithInp ut
End If
SharonKY
"TC" <a@b.c.d> wrote in message news:<106972502 1.674676@teutho s>... Sure, you would put the OpenForm (to open the next form) in the "true" part of the if-test, for example:
if nz (dlookup(true, "XXX", "FFF=999"), false) then ' it DOES exist. docmd.openform ... else msg "That number is not on file" endif
HTH, TC
"swathky" <sw*****@integr anetics.com> wrote in message news:2b******** *************** ***@posting.goo gle.com... Thanks so much, TC. I'll give this a shot - I'm assuming I'll work this in when the Answer <> "" Then ...right before telling the form to open the next form? Sharonky "TC" <a@b.c.d> wrote in message news:<106947573 1.952084@teutho s>... If you want to check whether there is a record in table XXX where the value of field FFF is 999:
if nz (dlookup(true, "XXX", "FFF=999"), false) then ' it DOES eist. else ' it DOES NOT exist. endif
Use your own values for XXX, FFF and 999.
HTH, TC
"swathky" <sw*****@integr anetics.com> wrote in message news:2b******** *************** **@posting.goog le.com... > I've tried mutiple things but no go -- (sorry this is so long) > I'm collecting a 5 digit number in an input box function and all works > fine until a number is passed that doesn't exist in the database. I > can't figure out where/how to check that the number exists before I > get the error code 2105. Here's my function to get the number that I > run when a command button is clicked to open the frmEditLoans form: > > Public Function GoToLoanWithInp ut() > Dim Msg, Title, Defvalue, Answer, Cancel > > Msg = "Enter VIN # last five digits" _ > & vbCrLf & vbCrLf & "Quick Tip: if you do not know Vin #," _ > & vbCrLf & " Copy and Paste from the ""Last 5 digits of Vin #""" _ > & vbCrLf & "field on the Edit menu's View Loan/Find Loan form." > > Title = "Open Edit Loan Form" > > Defvalue = "00000" > > Answer = InputBox(Msg, Title, Defvalue) > > If Answer = "00000" Then > MsgBox ("You need to enter a valid VIN ID #") > Call GoToLoanWithInp ut > Exit Function > End If > > If Answer = "" Then > If IsLoaded("frmEd itLoans") Then > DoCmd.Close acForm, "frmEditLoa ns" > End If > DoCmd.OpenForm "Switchboar d" > End If > > If Answer <> "" Then > DoCmd.OpenForm "frmEditLoa ns", , , "Right([VehicleVin],5)='" & > Answer & "' " > Exit Function > End If > > End Function > > Here's my unrelated conditional code that kicks in On Open event of > frmEditLoans: > > Private Sub Form_Open(Cance l As Integer) > > If IsDate(Me.Last_ Statement) Then > LoanOrigDate.En abled = False > Else > Me.LoanOrigDate .Enabled = True > (!**! debug highlights this:) Me.LoanOrigDate .SetFocus > If Me.CurtailmentR eq.Value = "No" Then > Me.CurtailmentP aymentAmount.Vi sible = False > Me.FirstPayDueD ate.Visible = False > Else: Me.CurtailmentP aymentAmount.Vi sible = True > Me.FirstPayDueD ate.Visible = True > End If > End If > End Sub > > If the VIN # doesn't exist, the runTime error 2105 "You can't go to > specified record." appears. Clicking debug highlights at the !**! > above. Putting the error in a Sub Form_Error event doesn't seem to > work unless I'm not contructing it correctly--which is possible. > I've learned so much from reading your answers to other people's > problems. Hope you can help me now. > Sharon
Er, you are assuming that every VIN number that is on file, will evaluate as
True. (That is because the result of the DLookup is the value of [Last5],
and that result is being used directly in an If-test.)
That assumption may well be true. But why make it, when you do not have to?
It would be safer, IMO, to do something like this. Then it doesn't matter
whether VIN numbers, if used in an If-test, would evaluate to True, or
False. If DLookup("[Last5], "qryValVinCurre nt", "[Last5] ='" & Answer & "' ") =
Answer Then
or:
If DLookup(1, "qryValVinCurre nt", "[Last5] ='" & Answer & "' ") = 1 Then
or (my favourite):
If nz (DLookup(True, "qryValVinCurre nt", "[Last5] ='" & Answer & "' "),
False) Then
Be aware that DLookup() returns NULL if a match is not found. And NULL does
not ever meet any test. Your code could get hit by that (in certain cases).
The last suggested format is the only one that is really safe, in all cases.
HTH,
TC
"swathky" <sw*****@integr anetics.com> wrote in message
news:2b******** *************** ***@posting.goo gle.com... Yes! this works. Point well taken, Larry, I tried several error handling lines that didn't work before I wrote in, and, since I couldn't get them to do what I wanted, I apparently still have a great deal to learn there. Thanks again, TC!
'check to see if valid VIN # If DLookup("[Last5]", "qryValVinCurre nt", "[Last5] ='" & Answer & "' ") Then DoCmd.OpenForm "frmEditLoa ns", , , "Right([VehicleVin],5)='" & Answer & "' " Else
'VIN# doesn't exist MsgBox ("The VIN # you entered is not valid." & Chr(13) & "Please verify # and try again.") Call GoToLoanWithInp ut
End If
SharonKY
"TC" <a@b.c.d> wrote in message news:<106972502 1.674676@teutho s>... Sure, you would put the OpenForm (to open the next form) in the "true"
part of the if-test, for example:
if nz (dlookup(true, "XXX", "FFF=999"), false) then ' it DOES exist. docmd.openform ... else msg "That number is not on file" endif
HTH, TC
"swathky" <sw*****@integr anetics.com> wrote in message news:2b******** *************** ***@posting.goo gle.com... Thanks so much, TC. I'll give this a shot - I'm assuming I'll work this in when the Answer <> "" Then ...right before telling the form to open the next form? Sharonky "TC" <a@b.c.d> wrote in message news:<106947573 1.952084@teutho s>... > If you want to check whether there is a record in table XXX where
the value > of field FFF is 999: > > if nz (dlookup(true, "XXX", "FFF=999"), false) then > ' it DOES eist. > else > ' it DOES NOT exist. > endif > > Use your own values for XXX, FFF and 999. > > HTH, > TC > > > "swathky" <sw*****@integr anetics.com> wrote in message > news:2b******** *************** **@posting.goog le.com... > > I've tried mutiple things but no go -- (sorry this is so long) > > I'm collecting a 5 digit number in an input box function and all
works > > fine until a number is passed that doesn't exist in the database.
I > > can't figure out where/how to check that the number exists before
I > > get the error code 2105. Here's my function to get the number
that I > > run when a command button is clicked to open the frmEditLoans
form: > > > > Public Function GoToLoanWithInp ut() > > Dim Msg, Title, Defvalue, Answer, Cancel > > > > Msg = "Enter VIN # last five digits" _ > > & vbCrLf & vbCrLf & "Quick Tip: if you do not know Vin #," _ > > & vbCrLf & " Copy and Paste from the ""Last 5 digits of Vin
#""" _ > > & vbCrLf & "field on the Edit menu's View Loan/Find Loan
form." > > > > Title = "Open Edit Loan Form" > > > > Defvalue = "00000" > > > > Answer = InputBox(Msg, Title, Defvalue) > > > > If Answer = "00000" Then > > MsgBox ("You need to enter a valid VIN ID #") > > Call GoToLoanWithInp ut > > Exit Function > > End If > > > > If Answer = "" Then > > If IsLoaded("frmEd itLoans") Then > > DoCmd.Close acForm, "frmEditLoa ns" > > End If > > DoCmd.OpenForm "Switchboar d" > > End If > > > > If Answer <> "" Then > > DoCmd.OpenForm "frmEditLoa ns", , ,
"Right([VehicleVin],5)='" & > > Answer & "' " > > Exit Function > > End If > > > > End Function > > > > Here's my unrelated conditional code that kicks in On Open event
of > > frmEditLoans: > > > > Private Sub Form_Open(Cance l As Integer) > > > > If IsDate(Me.Last_ Statement) Then > > LoanOrigDate.En abled = False > > Else > > Me.LoanOrigDate .Enabled = True > > (!**! debug highlights this:) Me.LoanOrigDate .SetFocus > > If Me.CurtailmentR eq.Value = "No" Then > > Me.CurtailmentP aymentAmount.Vi sible = False > > Me.FirstPayDueD ate.Visible = False > > Else: Me.CurtailmentP aymentAmount.Vi sible = True > > Me.FirstPayDueD ate.Visible = True > > End If > > End If > > End Sub > > > > If the VIN # doesn't exist, the runTime error 2105 "You can't go
to > > specified record." appears. Clicking debug highlights at the !**! > > above. Putting the error in a Sub Form_Error event doesn't seem to > > work unless I'm not contructing it correctly--which is possible. > > I've learned so much from reading your answers to other people's > > problems. Hope you can help me now. > > Sharon
Why go to all the bother if checking that a record exists? Surely
you're only slowing things up. If error 2105 means that the record
isn't there (I haven't looked it up so make sure that this is what is
causing the error), just write an error handler to trap error 2105 &
warn the user that this number doesn't exist / is mistyped? As one of
the other posters pointed out this isn't the only thing that can go
wrong here, so you're going to need some sort of error handler anyway.
OK, TC, I'll do your favorite way. I thought I didn't have to use NZ
since I thought I covered nulls with the statement 'If Answer = ""
Then do some things'.
Thanks to all for your input & help.
Sharon
"TC" <a@b.c.d> wrote in message news:<106981850 0.872406@teutho s>... Er, you are assuming that every VIN number that is on file, will evaluate as True. (That is because the result of the DLookup is the value of [Last5], and that result is being used directly in an If-test.)
That assumption may well be true. But why make it, when you do not have to? It would be safer, IMO, to do something like this. Then it doesn't matter whether VIN numbers, if used in an If-test, would evaluate to True, or False.
If DLookup("[Last5], "qryValVinCurre nt", "[Last5] ='" & Answer & "' ") = Answer Then
or:
If DLookup(1, "qryValVinCurre nt", "[Last5] ='" & Answer & "' ") = 1 Then
or (my favourite):
If nz (DLookup(True, "qryValVinCurre nt", "[Last5] ='" & Answer & "' "), False) Then
Be aware that DLookup() returns NULL if a match is not found. And NULL does not ever meet any test. Your code could get hit by that (in certain cases). The last suggested format is the only one that is really safe, in all cases.
HTH, TC
"swathky" <sw*****@integr anetics.com> wrote in message news:2b******** *************** ***@posting.goo gle.com... Yes! this works. Point well taken, Larry, I tried several error handling lines that didn't work before I wrote in, and, since I couldn't get them to do what I wanted, I apparently still have a great deal to learn there. Thanks again, TC!
'check to see if valid VIN # If DLookup("[Last5]", "qryValVinCurre nt", "[Last5] ='" & Answer & "' ") Then DoCmd.OpenForm "frmEditLoa ns", , , "Right([VehicleVin],5)='" & Answer & "' " Else
'VIN# doesn't exist MsgBox ("The VIN # you entered is not valid." & Chr(13) & "Please verify # and try again.") Call GoToLoanWithInp ut
End If
SharonKY
"TC" <a@b.c.d> wrote in message news:<106972502 1.674676@teutho s>... Sure, you would put the OpenForm (to open the next form) in the "true" part of the if-test, for example:
if nz (dlookup(true, "XXX", "FFF=999"), false) then ' it DOES exist. docmd.openform ... else msg "That number is not on file" endif
HTH, TC
"swathky" <sw*****@integr anetics.com> wrote in message news:2b******** *************** ***@posting.goo gle.com... > Thanks so much, TC. I'll give this a shot - I'm assuming I'll work > this in when the Answer <> "" Then ...right before telling the form to > open the next form? > Sharonky > > > > "TC" <a@b.c.d> wrote in message news:<106947573 1.952084@teutho s>... > > If you want to check whether there is a record in table XXX where the value > > of field FFF is 999: > > > > if nz (dlookup(true, "XXX", "FFF=999"), false) then > > ' it DOES eist. > > else > > ' it DOES NOT exist. > > endif > > > > Use your own values for XXX, FFF and 999. > > > > HTH, > > TC > > > > > > "swathky" <sw*****@integr anetics.com> wrote in message > > news:2b******** *************** **@posting.goog le.com... > > > I've tried mutiple things but no go -- (sorry this is so long) > > > I'm collecting a 5 digit number in an input box function and all works > > > fine until a number is passed that doesn't exist in the database. I > > > can't figure out where/how to check that the number exists before I > > > get the error code 2105. Here's my function to get the number that I > > > run when a command button is clicked to open the frmEditLoans form: > > > > > > Public Function GoToLoanWithInp ut() > > > Dim Msg, Title, Defvalue, Answer, Cancel > > > > > > Msg = "Enter VIN # last five digits" _ > > > & vbCrLf & vbCrLf & "Quick Tip: if you do not know Vin #," _ > > > & vbCrLf & " Copy and Paste from the ""Last 5 digits of Vin #""" _ > > > & vbCrLf & "field on the Edit menu's View Loan/Find Loan form." > > > > > > Title = "Open Edit Loan Form" > > > > > > Defvalue = "00000" > > > > > > Answer = InputBox(Msg, Title, Defvalue) > > > > > > If Answer = "00000" Then > > > MsgBox ("You need to enter a valid VIN ID #") > > > Call GoToLoanWithInp ut > > > Exit Function > > > End If > > > > > > If Answer = "" Then > > > If IsLoaded("frmEd itLoans") Then > > > DoCmd.Close acForm, "frmEditLoa ns" > > > End If > > > DoCmd.OpenForm "Switchboar d" > > > End If > > > > > > If Answer <> "" Then > > > DoCmd.OpenForm "frmEditLoa ns", , , "Right([VehicleVin],5)='" & > > > Answer & "' " > > > Exit Function > > > End If > > > > > > End Function > > > > > > Here's my unrelated conditional code that kicks in On Open event of > > > frmEditLoans: > > > > > > Private Sub Form_Open(Cance l As Integer) > > > > > > If IsDate(Me.Last_ Statement) Then > > > LoanOrigDate.En abled = False > > > Else > > > Me.LoanOrigDate .Enabled = True > > > (!**! debug highlights this:) Me.LoanOrigDate .SetFocus > > > If Me.CurtailmentR eq.Value = "No" Then > > > Me.CurtailmentP aymentAmount.Vi sible = False > > > Me.FirstPayDueD ate.Visible = False > > > Else: Me.CurtailmentP aymentAmount.Vi sible = True > > > Me.FirstPayDueD ate.Visible = True > > > End If > > > End If > > > End Sub > > > > > > If the VIN # doesn't exist, the runTime error 2105 "You can't go to > > > specified record." appears. Clicking debug highlights at the !**! > > > above. Putting the error in a Sub Form_Error event doesn't seem to > > > work unless I'm not contructing it correctly--which is possible. > > > I've learned so much from reading your answers to other people's > > > problems. Hope you can help me now. > > > Sharon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John C |
last post by:
Hi, I am a little uncertain about the concept of passing a reference to a
class to another instance of a class. for instance I thought that the
following was ok:
Network network = Network();
Population pool = Population(& network);
.... but this doesnt seem to work.. however the following works...
Network * network = new Network();
|
by: simonmarkjones |
last post by:
I want to validate my form using a BeforeUpdate event.
However now that i call my code with a beforeupdate it wont let me go
to next or previous records.
What code should i put in o allow me to do thi??
|
by: samotek |
last post by:
Can i avoid the appearance of the Run time error 2105?
I have a function that performs well,but at the end
the Run time error 2105 appears :" You cant go to the
specified record"
However when i click "End" on the window, i go to the
desired place and my function will be perfect if i can
|
by: Rico Singleton |
last post by:
I currently have an asp page that contains a simple form and a few
hidden fields. One of those hidden fields retrieves a value passed in
when a link is clicked that passes a value (i.e
http://www.somewhere.com/contact.asp?52 )
The code works fine on as an asp page on IIS 5.5 however, in trying to
migrate the pages on to IIS 6.0 with .NET Framework enabled, I get a
Runtime error everytime this value " " is used.
The current code that...
|
by: ged |
last post by:
Hi,
i am a oo (c#) programmer, and have not used javascript for a while and
i cant work out how javascript manages its references. Object
References work for simple stuff, but once i have an object collection
and stanrd using it it starts to fall apart.
Clearly there is something about javascript's usage of passing "By ref"
that i am not getting. i have had a look on the web and found some
examples, but i cant see why my code does not...
| |
by: Bobby |
last post by:
Hi
I have a form which I need to call from several different parts of my
application. Depending on where it is called from, the Data source
will change. The only way I know of to open a form from VBA is to use
DoCmd.OpenForm. However, is there any way I can pass the data source
as well? I've tried using the OpenArgs parameter, which partially
works, but I have code on form.current which does a recordsetclone.
When it gets to this I get a...
|
by: David01 |
last post by:
When I run some code behind a button i get a runtime error message. The strange thing is that the code run perfectly some months ago. Can some one help me !
Some additional information: The company I work for upgraded the citrix enviremont.
Here is the code:
Private Sub knptoevoegen_Click()
On Error GoTo err_knptoevoegen_click
Dim filid As Variant
Dim beursid As Variant
Dim fout As Integer
|
by: Shashank |
last post by:
Hi,
I am passing a tcpdump filter to a function which compiles the filter
using pcap_compile and then sets it.
Here is the filter,
ip>=0x0000 and ip <=0xd9295a3 and ip >=0x0000 and
ip <=0x3ca9b416 and tcp>=0 and tcp<=23923 and
tcp>=0 and tcp<=64582 and tcp<=655355
I have many threads passing different filters of a similar form to
|
by: scottbouley |
last post by:
I'm new at adding VBA to Access 2007 and could really use some help.
I have two forms used to gather data to go into a datasheet subform. The following code on the second of the two forms populates the subform:
Private Sub OK_Click()
If ( > ) Then
MsgBox "Sales Quantity cannot exceed Quantity In Stock", vbOKOnly
.SetFocus
Exit Sub
Else
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |