Advertisement

06.04.2008 at 10:10AM PDT, ID: 23457502
[x]
Attachment Details

Null records using  If Then Else Statement

Asked by filtrationproducts in Microsoft Access Database, Databases Miscellaneous, Access Forms

Tags: Microsoft, Access, 2003

I have a form (Form1) with a button, ID field and a checkbox field(me.mrb).

I coded the button so if the check box is equal to 0 it will open a different form (Form1) showing all the records

I followed that with an "else" statement that instructs it to open Form2 to whatever record is in the "ID" field at the time.

Everything works just as I want it to except when I am in Form1 and not under a record (ID field = "autonumber") and i click the button the database crashes out and closes.

I attached the code below. I think I need to add a elseif statement that says "if ID field = "autonumber?" or "null?" then just open with all records but I am not sure how to code it.
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
Private Sub Command101_Click()
 
If Me.MRB >= 0 Then
    
    Dim stDocName2 As String
    Dim stLinkCriteria2 As String
 
    stDocName2 = "F824005 - MRB Inspection"
    DoCmd.OpenForm stDocName2, , , stLinkCriteria2
   
Else
 
    Dim stDocName As String
    Dim stLinkCriteria As String
 
    stDocName = "F824005 - MRB Inspection"
    
    stLinkCriteria = "[ID]=" & Me![ID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
  
 
    
End If
 
End Sub
 
Loading Advertisement...
 
[+][-]06.04.2008 at 10:18AM PDT, ID: 21712111

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Access Database, Databases Miscellaneous, Access Forms
Tags: Microsoft, Access, 2003
Sign Up Now!
Solution Provided By: nexusnation
Participating Experts: 1
Solution Grade: A
 
 
[+][-]06.04.2008 at 10:35AM PDT, ID: 21712224

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 10:39AM PDT, ID: 21712260

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628