Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordset blows up with error 3077 1

Status
Not open for further replies.

MacroAlan

Programmer
Dec 4, 2006
134
US
I need to find out if a name exists in the table before inserting it. I do not want to have duplicates.

I wrote a piece of codde to put the field into a RecordSet and look for the name:
Code:
Sub FindDSname(setNum) [red]pass value to search[/red]
    Dim striXer As String, sroad As Long
    Dim RS      As Recordset
    Dim DB      As Database
    Dim strSQL  As String
    
    strSQL = "SELECT DataSetName FROM DataSets"   [red] 'Table[/red]
    Set DB = CurrentDb()
    Set RS = DB.OpenRecordset(strSQL, dbOpenSnapshot)
    
    Do While Not RS.EOF
        RS.FindFirst setNum  [red]blows up here with 3077 Missing operator in expression[/red]
    
    If RS.NoMatch Then
        sqlString = InsertString & ", DateStamp, Userid ,SetName,CompanyName)" & ValueString & " #" & Now() & "# AS DateStamp, " _
            & Chr(34) & Environ("USERNAME") & Chr(34) & " AS Userid, " & DSN & " AS SetName, " _
            & Company & " AS CompanyName" _
            & " FROM tempImport;" [red]'write to table if don't exist[/red]
        DoCmd.RunSQL sqlString
        Exit Sub
    Else
        'Record Found
        MsgBox "That name already exists"
        Exit Sub
    End If
    Loop
    
    RS.Close
Am I even on the right path to the answer??

Alan

 
Why not simply this ?
If IsNull(DLookUp("DataSetName", "DataSets", "DataSetName='" & setNum & "'")) Then

Note: if DataSetName is defined as numeric in DataSets then get rid of the single quotes.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top