OpenRecordset Loop (1 Viewer)

damian

Registered User.
Local time
Today, 17:51
Joined
Jun 27, 2004
Messages
87
Hi

Attempting to adapt some VBA in order to sequentially number a field (named Code) based upon whether another field (txtimagename) is either blank or Is Null.

Code I have to date for a button on my form:

Code:
Dim dbc As Database
Dim rst As Recordset

Dim i As Long
        i = 1
            Set dbc = CurrentDb()
            Set rst = dbc.OpenRecordset("select * from TBL_SurveyDetail ORDER BY TBL_SurveyDetail.SurveyDetailMainFormLinkNumber, TBL_SurveyDetail.DistanceM, TBL_SurveyDetail.txtimagename;")
                Do While Not rst.EOF
                rst.Edit
                rst!Code = i
                rst.Update
                rst.MoveNext
                i = i + 1
            Loop
    rst.Close



This code works on the table but currently will number the 'Code' field irrespective of whether txtimagename is null/empty or not. Have tinkered with a 'where clause' but struggling with the syntax - any pointers/assistance would be greatly appreciated
 

damian

Registered User.
Local time
Today, 17:51
Joined
Jun 27, 2004
Messages
87
When I attempt to include following 'Where' clause, results in syntax error 3075:

Set rst = dbc.OpenRecordset("select * from TBL_SurveyDetail where (((TBL_SurveyDetail.txtimagename)<>"")) ORDER BY TBL_SurveyDetail.SurveyDetailMainFormLinkNumber, TBL_SurveyDetail.DistanceM, TBL_SurveyDetail.txtimagename;")
 

mdlueck

Sr. Application Developer
Local time
Today, 12:51
Joined
Jun 23, 2011
Messages
2,631

damian

Registered User.
Local time
Today, 17:51
Joined
Jun 27, 2004
Messages
87
Cheers, got confused with all the quotation mark business so decided to simply reference a query that filtered out the information instead.
 

Users who are viewing this thread

Top Bottom