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

Open a form to search for a record using a command button which prompts input box

P: 64
Are this the correct coding for if else statement for the input box?
Can help me?

Expand|Select|Wrap|Line Numbers
  1. Dim Search As String, Message As String
  2. Search = "Find RF"
  3. Message = InputBox(Prompt, "Search")
  4. If Message <> RF_NO Then
  5. MsgBox "Data not exist"
  6. Else
  7. DoCmd.OpenForm "Product_Requisition", acNormal, , "[RF_no] Like '" & Message & "*'"
  8. MsgBox "Data exist"
  9. End If
Feb 26 '15 #1
Share this Question
Share on Google+
5 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,486
mrijet,

It is unclear from your code what "RF_NO" is. It seems to be listed as a variable, but it is neither declared nor set anywhere to say what it is.

If it is a control on a Form, then your code will only check to see if the input value matches what is currently displayed on your form, but will not "find" any record for you.

All that aside, if you were to delete lines 4-6 and line 9, the command to open a form "should" work, assuming all field names are correct.
Feb 27 '15 #2

P: 64
Actually I choose to make a condition such as if I put the RF_no, they will find me the RF_no that exist for me..and if the RF_no did not exist it will show message box to me that show the data not exist...

So, did the coding I sent it was correct or not...or maybe you can help me? mrtwinnyfo
Mar 11 '15 #3

twinnyfo
Expert Mod 2.5K+
P: 3,486
Again,

You have to help us out here. Your code provided does not tell us anything about what is going on. Is the Form Bound? We still don't know if RF_No is a variable or a control on a form or an underlying field in a table (we assume from one of your other posts that it is a field name).

However, without this information, it is difficult to guide to a solution. Standing by to assist as necessary.....
Mar 11 '15 #4

P: 64
Expand|Select|Wrap|Line Numbers
  1. Dim lngID As String
  2.  
  3. lngID = InputBox("Enter RF No")
  4. If lngID = "" Then
  5. DoCmd.ClearMacroError
  6. Else
  7. DoCmd.OpenReport "Requisition_ReportComplete", acViewReport, , "[RF_no]=" & lngID
  8. End If
As you see the code above is for searching specific data and it's actually can work without any error..

But if I add this coding....

Expand|Select|Wrap|Line Numbers
  1. Dim lngID As String
  2.  
  3. lngID = InputBox("Enter RF No")
  4. If lngID = "" Then
  5. DoCmd.ClearMacroError
  6. ElseIf lngID <> RF_no Then
  7. MsgBox "Data not exist"
  8. Else
  9. DoCmd.OpenReport "Requisition_ReportComplete", acViewReport, , "[RF_no]=" & lngID
  10. End If
And put none exist data it will not go the coding that I bold it...
Can help me?

mr twinnyfo
Mar 12 '15 #5

twinnyfo
Expert Mod 2.5K+
P: 3,486
Please answer the questions of Post #4 and I can guide you toward a solution.
Mar 12 '15 #6

Post your reply

Sign in to post your reply or Sign up for a free account.