473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Passing typo to form gets runtime error 2105

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 GoToLoanWithInput()
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 GoToLoanWithInput
Exit Function
End If

If Answer = "" Then
If IsLoaded("frmEditLoans") Then
DoCmd.Close acForm, "frmEditLoans"
End If
DoCmd.OpenForm "Switchboard"
End If

If Answer <> "" Then
DoCmd.OpenForm "frmEditLoans", , , "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(Cancel As Integer)

If IsDate(Me.Last_Statement) Then
LoanOrigDate.Enabled = False
Else
Me.LoanOrigDate.Enabled = True
(!**! debug highlights this:) Me.LoanOrigDate.SetFocus
If Me.CurtailmentReq.Value = "No" Then
Me.CurtailmentPaymentAmount.Visible = False
Me.FirstPayDueDate.Visible = False
Else: Me.CurtailmentPaymentAmount.Visible = True
Me.FirstPayDueDate.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
Nov 12 '05 #1
8 5138
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:<1069475731.952084@teuthos>...
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*****@integranetics.com> wrote in message
news:2b*************************@posting.google.co m...
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 GoToLoanWithInput()
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 GoToLoanWithInput
Exit Function
End If

If Answer = "" Then
If IsLoaded("frmEditLoans") Then
DoCmd.Close acForm, "frmEditLoans"
End If
DoCmd.OpenForm "Switchboard"
End If

If Answer <> "" Then
DoCmd.OpenForm "frmEditLoans", , , "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(Cancel As Integer)

If IsDate(Me.Last_Statement) Then
LoanOrigDate.Enabled = False
Else
Me.LoanOrigDate.Enabled = True
(!**! debug highlights this:) Me.LoanOrigDate.SetFocus
If Me.CurtailmentReq.Value = "No" Then
Me.CurtailmentPaymentAmount.Visible = False
Me.FirstPayDueDate.Visible = False
Else: Me.CurtailmentPaymentAmount.Visible = True
Me.FirstPayDueDate.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

Nov 12 '05 #2
TC
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*****@integranetics.com> wrote in message
news:2b*************************@posting.google.co m...
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 GoToLoanWithInput()
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 GoToLoanWithInput
Exit Function
End If

If Answer = "" Then
If IsLoaded("frmEditLoans") Then
DoCmd.Close acForm, "frmEditLoans"
End If
DoCmd.OpenForm "Switchboard"
End If

If Answer <> "" Then
DoCmd.OpenForm "frmEditLoans", , , "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(Cancel As Integer)

If IsDate(Me.Last_Statement) Then
LoanOrigDate.Enabled = False
Else
Me.LoanOrigDate.Enabled = True
(!**! debug highlights this:) Me.LoanOrigDate.SetFocus
If Me.CurtailmentReq.Value = "No" Then
Me.CurtailmentPaymentAmount.Visible = False
Me.FirstPayDueDate.Visible = False
Else: Me.CurtailmentPaymentAmount.Visible = True
Me.FirstPayDueDate.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

Nov 12 '05 #3
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*****@integranetics.com> wrote in message
news:2b**************************@posting.google.c om...
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:<1069475731.952084@teuthos>...
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*****@integranetics.com> wrote in message
news:2b*************************@posting.google.co m...
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 GoToLoanWithInput()
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 GoToLoanWithInput
Exit Function
End If

If Answer = "" Then
If IsLoaded("frmEditLoans") Then
DoCmd.Close acForm, "frmEditLoans"
End If
DoCmd.OpenForm "Switchboard"
End If

If Answer <> "" Then
DoCmd.OpenForm "frmEditLoans", , , "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(Cancel As Integer)

If IsDate(Me.Last_Statement) Then
LoanOrigDate.Enabled = False
Else
Me.LoanOrigDate.Enabled = True
(!**! debug highlights this:) Me.LoanOrigDate.SetFocus
If Me.CurtailmentReq.Value = "No" Then
Me.CurtailmentPaymentAmount.Visible = False
Me.FirstPayDueDate.Visible = False
Else: Me.CurtailmentPaymentAmount.Visible = True
Me.FirstPayDueDate.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

Nov 12 '05 #4
TC
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*****@integranetics.com> wrote in message
news:2b**************************@posting.google.c om...
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:<1069475731.952084@teuthos>...
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*****@integranetics.com> wrote in message
news:2b*************************@posting.google.co m...
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 GoToLoanWithInput()
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 GoToLoanWithInput
Exit Function
End If

If Answer = "" Then
If IsLoaded("frmEditLoans") Then
DoCmd.Close acForm, "frmEditLoans"
End If
DoCmd.OpenForm "Switchboard"
End If

If Answer <> "" Then
DoCmd.OpenForm "frmEditLoans", , , "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(Cancel As Integer)

If IsDate(Me.Last_Statement) Then
LoanOrigDate.Enabled = False
Else
Me.LoanOrigDate.Enabled = True
(!**! debug highlights this:) Me.LoanOrigDate.SetFocus
If Me.CurtailmentReq.Value = "No" Then
Me.CurtailmentPaymentAmount.Visible = False
Me.FirstPayDueDate.Visible = False
Else: Me.CurtailmentPaymentAmount.Visible = True
Me.FirstPayDueDate.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

Nov 12 '05 #5
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]", "qryValVinCurrent", "[Last5] ='" & Answer
& "' ") Then
DoCmd.OpenForm "frmEditLoans", , , "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 GoToLoanWithInput

End If

SharonKY

"TC" <a@b.c.d> wrote in message news:<1069725021.674676@teuthos>...
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*****@integranetics.com> wrote in message
news:2b**************************@posting.google.c om...
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:<1069475731.952084@teuthos>...
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*****@integranetics.com> wrote in message
news:2b*************************@posting.google.co m...
> 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 GoToLoanWithInput()
> 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 GoToLoanWithInput
> Exit Function
> End If
>
> If Answer = "" Then
> If IsLoaded("frmEditLoans") Then
> DoCmd.Close acForm, "frmEditLoans"
> End If
> DoCmd.OpenForm "Switchboard"
> End If
>
> If Answer <> "" Then
> DoCmd.OpenForm "frmEditLoans", , , "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(Cancel As Integer)
>
> If IsDate(Me.Last_Statement) Then
> LoanOrigDate.Enabled = False
> Else
> Me.LoanOrigDate.Enabled = True
> (!**! debug highlights this:) Me.LoanOrigDate.SetFocus
> If Me.CurtailmentReq.Value = "No" Then
> Me.CurtailmentPaymentAmount.Visible = False
> Me.FirstPayDueDate.Visible = False
> Else: Me.CurtailmentPaymentAmount.Visible = True
> Me.FirstPayDueDate.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

Nov 12 '05 #6
TC
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], "qryValVinCurrent", "[Last5] ='" & Answer & "' ") = Answer Then

or:
If DLookup(1, "qryValVinCurrent", "[Last5] ='" & Answer & "' ") = 1 Then
or (my favourite):
If nz (DLookup(True, "qryValVinCurrent", "[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*****@integranetics.com> wrote in message
news:2b**************************@posting.google.c om... 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]", "qryValVinCurrent", "[Last5] ='" & Answer
& "' ") Then
DoCmd.OpenForm "frmEditLoans", , , "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 GoToLoanWithInput

End If

SharonKY

"TC" <a@b.c.d> wrote in message news:<1069725021.674676@teuthos>...
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*****@integranetics.com> wrote in message
news:2b**************************@posting.google.c om...
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:<1069475731.952084@teuthos>...
> 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*****@integranetics.com> wrote in message
> news:2b*************************@posting.google.co m...
> > 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 GoToLoanWithInput()
> > 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 GoToLoanWithInput
> > Exit Function
> > End If
> >
> > If Answer = "" Then
> > If IsLoaded("frmEditLoans") Then
> > DoCmd.Close acForm, "frmEditLoans"
> > End If
> > DoCmd.OpenForm "Switchboard"
> > End If
> >
> > If Answer <> "" Then
> > DoCmd.OpenForm "frmEditLoans", , , "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(Cancel As Integer)
> >
> > If IsDate(Me.Last_Statement) Then
> > LoanOrigDate.Enabled = False
> > Else
> > Me.LoanOrigDate.Enabled = True
> > (!**! debug highlights this:) Me.LoanOrigDate.SetFocus
> > If Me.CurtailmentReq.Value = "No" Then
> > Me.CurtailmentPaymentAmount.Visible = False
> > Me.FirstPayDueDate.Visible = False
> > Else: Me.CurtailmentPaymentAmount.Visible = True
> > Me.FirstPayDueDate.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

Nov 12 '05 #7
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.
Nov 12 '05 #8
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:<1069818500.872406@teuthos>...
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], "qryValVinCurrent", "[Last5] ='" & Answer & "' ") =

Answer Then

or:
If DLookup(1, "qryValVinCurrent", "[Last5] ='" & Answer & "' ") = 1 Then


or (my favourite):
If nz (DLookup(True, "qryValVinCurrent", "[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*****@integranetics.com> wrote in message
news:2b**************************@posting.google.c om...
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]", "qryValVinCurrent", "[Last5] ='" & Answer
& "' ") Then
DoCmd.OpenForm "frmEditLoans", , , "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 GoToLoanWithInput

End If

SharonKY

"TC" <a@b.c.d> wrote in message news:<1069725021.674676@teuthos>...
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*****@integranetics.com> wrote in message
news:2b**************************@posting.google.c om...
> 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:<1069475731.952084@teuthos>...
> > 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*****@integranetics.com> wrote in message
> > news:2b*************************@posting.google.co m...
> > > 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 GoToLoanWithInput()
> > > 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 GoToLoanWithInput
> > > Exit Function
> > > End If
> > >
> > > If Answer = "" Then
> > > If IsLoaded("frmEditLoans") Then
> > > DoCmd.Close acForm, "frmEditLoans"
> > > End If
> > > DoCmd.OpenForm "Switchboard"
> > > End If
> > >
> > > If Answer <> "" Then
> > > DoCmd.OpenForm "frmEditLoans", , , "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(Cancel As Integer)
> > >
> > > If IsDate(Me.Last_Statement) Then
> > > LoanOrigDate.Enabled = False
> > > Else
> > > Me.LoanOrigDate.Enabled = True
> > > (!**! debug highlights this:) Me.LoanOrigDate.SetFocus
> > > If Me.CurtailmentReq.Value = "No" Then
> > > Me.CurtailmentPaymentAmount.Visible = False
> > > Me.FirstPayDueDate.Visible = False
> > > Else: Me.CurtailmentPaymentAmount.Visible = True
> > > Me.FirstPayDueDate.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

Nov 12 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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();...
15
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...
1
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...
0
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...
6
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...
1
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...
7
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...
2
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...
11
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.