Help in ms access for query result

meenctg

Learn24bd
Local time
Today, 19:28
Joined
May 8, 2012
Messages
133
I created a query in ms access. In criteria a put [Enter a value : ] . I created a form of this query. When i open this form it shows a input box with “ Enter your value : “ when i put a value in this box and click ok. it shows result. but if the input value doesn’t exist this database then open a blank form.

My question is, can i open a design form if the input value doesn’t exits. Actually i want to when input value match it’ll show result form but when the input data doesn’t exist the database it’ll show a design form.

Please help me anyone if need VB code or easy method for this task.
 
Why would you want to open the Form in Design view?

Or did I misunderstand the question.
 
Why would you want to open the Form in Design view?

Or did I misunderstand the question.

For a good example i attached a photo like my plan.
please help me it need VB code for my plan
 

Attachments

  • help.png
    help.png
    43.1 KB · Views: 107
You need to do a record count on the query. If this is zero then open the second form.
 
Try this
Code:
Sub FindForm()
On Error GoTo ErrHandle
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("Your_Table_Name", dbOpenSnapshot)
MyForm = InputBox("Enter search value", "SEARCH VALUE")
strFind = "[Form_Name] = '" & MyForm & "'"
If rst.RecordCount <> 0 Then
    rst.MoveLast
    rst.FindFirst strFind
        If Not rst.NoMatch Then
            DoCmd.OpenForm MyForm
        Else
            DoCmd.OpenForm "MyDataEntryForm" 'used to add new data
        End If
End If
Exit Sub
ErrHandle:
MsgBox Err.Description
End Sub
 
Try this
Code:
Sub FindForm()
On Error GoTo ErrHandle
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("Your_Table_Name", dbOpenSnapshot)
[B]MyForm = InputBox("Enter search value", "SEARCH VALUE")[/B]
[B]strFind = "[Form_Name][/B] = '" & MyForm & "'"
If rst.RecordCount <> 0 Then
    rst.MoveLast
    rst.FindFirst strFind
        If Not rst.NoMatch Then
            DoCmd.OpenForm MyForm
        Else
            DoCmd.OpenForm "MyDataEntryForm" 'used to add new data
        End If
End If
Exit Sub
ErrHandle:
MsgBox Err.Description
End Sub

I m extremely sry cz i m not expert in VB. So would u tell me this code where will i put. I mean to say where i'll apply this code in my form? which i made from my query.

my created query name is srcFullfrm i made a form of this query that is sResult . I want to open a form ( form name Form2 )when entered data won't be exist. please help me.
 
Last edited:
I assume you use a Command Button to open the form.

If so you need to put this code in the On Click Event of that Command Button.

If I am not correct please advise what you do to open the form.
 
Correct, on the On_Click event
Copy the code below the Sub statement and above the End Sub and paste it in.

What is does is ask for your form name. If it finds it in your table ("Your_Table_Name"), it opens the form stored as a variable in MyForm.
Otherwise it opens the Data entry form.
 

Users who are viewing this thread

Back
Top Bottom