Application-defined or object-defined error (1 Viewer)

b0gdan

Me
Local time
Yesterday, 22:47
Joined
Oct 5, 2006
Messages
29
Hello,
I have the following code and i don`t know what's wrong
Private Sub cmdCautare_Click()
Dim strSQL As String, strOrder As String, strWhere As String
'Dim dbNm As Database
'Dim qryDef As QueryDef
'Set dbNm = CurrentDb()
strSQL = "SELECT DOSARE.DosarID,DOSARE.DenumireDosar,DOSARE.CodDosar,DOSARE.DataDosar,DOSARE.Denumire,DOSARE.Data,DOSARE.Stadiu FROM DOSARE"
strWhere = "WHERE"
strOrder = "ORDER BY DOSARE.DosarID "
If Not IsNull(Me.txtDenumire) Then
strWhere = strWhere & "(DOSARE.DenumireDosar) Like '*" & Me.txtDenumire & "*' AND" ' "
End If
If Not IsNull(Me.cmbStadiu) Then
strWhere = strWhere & " (DOSARE.Stadiu) Like '*" & Me.cmbStadiu & "*'"
End If
DoCmd.Close acForm, "frmPrincipal"
DoCmd.OpenForm "frmRezultateCautare", acNormal
Forms!frmRezultateCautare.RowSource = strSQL & " " & strWhere & "" & strOrder
End Sub

Here: Forms!frmRezultateCautare.RowSource = strSQL & " " & strWhere & "" & strOrder
The error is the following "Application-defined or object-defined error"

Thanks!
 

grnzbra

Registered User.
Local time
Today, 06:47
Joined
Dec 5, 2001
Messages
376
You don't have a space between the quotations between strWhere and strOrder. It also looks like you might have an extra quotation mark in the line that sets up strWhere.

I would construct the entire strSQL outside the setting of the rowsource. that way you can put in a breakpoint and look at what you've got.

strSQL = strSQL & " " & strWhere & " " & strOrder

Put in the breakpoint on the line following it, open the Immediate window and type in
?strSQL

You will see if the data source is what you are expecting.

Also, it looks as if you will have the word "AND" sloshing around loose at the end of your WHERE statement if there is no entry in cmbStadiu. If that's the case, you can either set up something on the form that will not let the processing continue until something is entered into cmbStadiu or add "AND" to the end of the cmbStadiu portion of the strWhere construction and then lop it off. Of course, you have made provision to check for an entry in either one of the parameters, but no check to deal with neither of them being there; you will still end up with strWhere saying "WHERE"
 
Last edited:

Users who are viewing this thread

Top Bottom