Why does this IF statement fail?

davesmith202

Employee of Access World
Local time
Today, 21:00
Joined
Jul 20, 2001
Messages
522
If (![Export]) = "Yes" Then
etc
end if

Export is a Yes/No field.

Thanks,

Dave
 
If me![Export] = Yes Then
etc
end if


????
 
Last edited:
Still not working. More of the code is below.

Code:
Private Sub cmdExport_Click()
Dim strAdwordsCSV As String
Dim strFileName As String
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("tblAdwords", dbOpenTable)
strAdwordsCSV = ""
With rst
    .MoveFirst
    Do Until .EOF
    If Me![Export] = Yes Then
        strKeywordList = Replace(txtKeywords, vbCrLf, ",")
        strAdwordsCSV = strAdwordsCSV & ![Campaign] & "," & ![MaxCPC] & "," & ![Adgroup] & "," & ![Title] & "," & ![Line1] & "," & ![Line2] & "," & ![DisplayURL] & "," & strKeywordList & Chr(10)
    End If
    .MoveNext
    Loop
End With
 
And what about:

If ![Export] = Yes Then
 
Well, when I do that it runs as though all fields called Export are equal to Yes. But they are not.
 
KenHigg said:
What about:

If ![Export] = -1 Then
-1 is the YES value and 0 is the NO value access stores in a Yes/No field.
 
ghudson said:
-1 is the YES value and 0 is the NO value access stores in a Yes/No field.

You need to use early binding and not late binding with the With keyword.
 
SJ McAbney said:
You need to use early binding and not late binding with the With keyword.

And just how would you change Daves sample code to do that?
 
Code:
Private Sub cmdExport_Click()
    Dim strAdwordsCSV As String
    Dim strFileName As String
    Dim db As DAO.Database
    Dim rst As DAO.Recordset

    Set db = CurrentDb()
    Set rst = db.OpenRecordset("tblAdwords", dbOpenTable)

    With rst
        .MoveFirst
        Do Until .EOF
        If Me.[Export] = True Then
            strKeywordList = Replace(txtKeywords, vbCrLf, ",")
            strAdwordsCSV = strAdwordsCSV & .Fields("Campaign") & "," & _
                .Fields("MaxCPC") & "," & .Fields("Adgroup") & "," & _
                .Fields("Title") & "," & .Fields("Line1") & "," & .Fields("Line2") & _
                "," & .Fields("DisplayURL") & "," & strKeywordList & vbCr
        End If
        .MoveNext
        Loop
    End With
End Sub
 
Hum...

The thinking being that this will take you straight to the field attribuites of the object instead of having to search to find out what the name is the name of...?
 
If you have not solutioned your problem yet, try writting "vbYes" in your code instead of "yes".
 

Users who are viewing this thread

Back
Top Bottom