By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,045 Members | 1,367 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,045 IT Pros & Developers. It's quick & easy.

inputbox and dlookup issues

P: n/a
dear respected Gurus,

i would like to know what is wrong with my codes, i wanted to put
PolicyNo(say any string value, which is PK in table)...how to do? as i
make one inputbox it asked the value, but says "you cancelled the
previous opertion"

Private Sub btnAdd_Click()
Dim msgTitle As String
Dim strInput As String
Dim lblInput As String
Dim varChk As Boolean

msgTitle = "New Policy No."
lblInput = "Enter new Policy No."
strInput = InputBox(lblInput, msgTitle)

varChk = DLookup(strInput, "[BURGLARY2000]", "[POLICYNO]=" & strInput)

If varChk = True Then
MsgBox "Policy Issued"
Else
MsgBox "Policy not Issued"
End If

regards,
your studnet
Shahzad
End Sub
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The problem is that you're using strInput twice in your DLookup statement:
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"MUHAMAMD SALIM SHAHZAD" <ms******@yahoo.ca> wrote in message
news:5a**************************@posting.google.c om...
dear respected Gurus,

i would like to know what is wrong with my codes, i wanted to put
PolicyNo(say any string value, which is PK in table)...how to do? as i
make one inputbox it asked the value, but says "you cancelled the
previous opertion"

Private Sub btnAdd_Click()
Dim msgTitle As String
Dim strInput As String
Dim lblInput As String
Dim varChk As Boolean

msgTitle = "New Policy No."
lblInput = "Enter new Policy No."
strInput = InputBox(lblInput, msgTitle)

varChk = DLookup(strInput, "[BURGLARY2000]", "[POLICYNO]=" & strInput)

If varChk = True Then
MsgBox "Policy Issued"
Else
MsgBox "Policy not Issued"
End If

regards,
your studnet
Shahzad
End Sub

Nov 13 '05 #2

P: n/a
Sorry, somehow that got sent before I was finished typing.

The first argument in DLookup is supposed to be a field name, not a value.

The other problem is that DLookup isn't going to return a Boolean value
(unless that's the data type of the field you're trying to return)

Try the following:

Private Sub btnAdd_Click()
Dim msgTitle As String
Dim strInput As String
Dim lblInput As String
Dim lngCount As Long

msgTitle = "New Policy No."
lblInput = "Enter new Policy No."
strInput = InputBox(lblInput, msgTitle)

lngCount = DCount("*", "[BURGLARY2000]", "[POLICYNO]=" & strInput)

If lngCount > 0 Then
MsgBox "Policy Issued"
Else
MsgBox "Policy not Issued"
End If
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:XW******************@news04.bloor.is.net.cabl e.rogers.com...
The problem is that you're using strInput twice in your DLookup statement:
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"MUHAMAMD SALIM SHAHZAD" <ms******@yahoo.ca> wrote in message
news:5a**************************@posting.google.c om...
dear respected Gurus,

Nov 13 '05 #3

P: n/a
ms******@yahoo.ca (MUHAMAMD SALIM SHAHZAD) wrote in
news:5a**************************@posting.google.c om:
dear respected Gurus,

i would like to know what is wrong with my codes, i wanted to
varChk = DLookup(strInput, "[BURGLARY2000]", "[POLICYNO]=" &
strInput)


Dlookup doesn't work the way you are trying to use it.

Try
varchk = not isnull(dlookup("[policyno]","[burglary_2000]",
"[Policyno]= '" & strinput " "'"))
Bob Quintal
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.