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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error 3044 on qry in VB

Status
Not open for further replies.

sonikudi

Technical User
Sep 9, 2007
81
US
Hello,

I am trying to basically run the qry below, but every time i run it , it gives me an error saying query must have atleast one destination field. So i went under queries and saw that the TempQry was blank.. I thought that the following code would automatically create a TempQry with the StrSQL qry in it..I am not sure whats wrong with my code. My program is in Access.

Code:
Private Sub Findit_Click()


On Error GoTo qry

Dim qdf As QueryDef
Dim StrSQL As String

StrSQL = "SELECT * FROM [PCB Incoming_Production Results] " & _
"WHERE [PCB SS #]= #Me.txtserialno# ORDER BY Date; "


' Create new QueryDef object, don't really need it once the query exists

Set qdf = CurrentDb.CreateQueryDef("TempQry", StrSQL)
' Open query in Datasheet view.

qry:
'if query exists
Set qdf = CurrentDb.QueryDefs("TempQry")

DoCmd.OpenQuery qdf.Name
Set dbs = Nothing

DoCmd.Close acForm, "PCBserialno", acSaveNo
End Sub
 
I would use a saved query and simply change its SQL property on the fly:
Code:
Private Sub Findit_Click()
  On Error GoTo qry
  Dim qdf As DAO.QueryDef
  Dim StrSQL As String

  StrSQL = "SELECT * FROM [PCB Incoming_Production Results] " & _
   "WHERE [PCB SS #]= """ & Me.txtserialno & """ ORDER BY [Date]; "


  ' Use an existing querydef. Don't delete it, just change its SQL property

  Set qdf = CurrentDb.QueryDefs("TempQry")
  ' Open query in Datasheet view.

  'if query exists
  qdf.SQL = strSQL

  DoCmd.OpenQuery qdf.Name
  DoCmd.Close acForm, "PCBserialno", acSaveNo
End Sub

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thanks Duane ..it worked!

Do you know if writing the SQL in VB as opposed to having it in access is better...? because sometimes when my query is in access and the user enters a serial no thats not in the Db or for , i am not exactly sure what reason, the SQL statement of the query in Access get automatically delted...I tried to enter a serial no that wasn't in the Db and as of now it doesn't delete the query in VB..but for any other user action could this happen again for my SQL string statement in VB or something similar??
 
I don't have a clue why a query would be deleted unless your code does this.

I generally create queries in the Access interface. However, when the SQL needs to regularly be updated, I use code to modify the SQL property.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top