PDA

View Full Version : Interrupted Inputs!



prabhafriend
03-06-2009, 03:55 AM
Hello Friends. I am Prabha Karan from Thanjavur (South India). I am currently working in a Retail Management Tool using Ms-Access. I made a menu command which on-action runs a procedure which asks the user to enter the number of the invoice (invoice_no) to open. I used an input-box to get the data from the user. There is no problem in open the corresponding invoice using the docmd command object. But the problem is if the user changes the mind to not open an old invoice, He has to click the cancel button to get rid of the displayed box. But I am getting an error while my user clicks the cancel button in that particular input box. Why? I am giving here the code… Kindly, explain why this is not happening in this way? If possible, tell me an alternate. Thanks in Advance.
Public Function open_invoice()
Docmd.openform “invoice”,acnormal,,invoice_no=inputbox(“Enter the invoice no and press Ok”)
End function

ritwik_ncj
03-06-2009, 04:41 AM
You need to code the cancel button.... try this




Public Function open_invoice()
Dim message, title, defaultValue As String
Dim myValue As Object
' Set prompt.
message = "Enter the invoice no and press Ok"
' Set title.
title = "invoice"
defaultValue = "" ' Set default value.

' Display message, title, and default value.
myValue = InputBox(message, title, defaultValue)
' If user has clicked Cancel, set myValue to defaultValue
If myValue Is <> "" Then
Docmd.openform “invoice”,acnormal,,invoice_no=myValue
Else
Exit
End IF

End function