Re: Problem using DAO

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Since you corrected the error with your SQL that I pointed out, you should
be able to use the dbOpenDynaset parameter now if you want. To be honest,
though, I don't think it really matters that much.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"JKarchner" <JKarchner@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:39D29553-495B-44C9-BD7C-24EA5246634D@xxxxxxxxxxxxxxxx
OK i made some changes to what i had and it works. As you can tell i took
out the dbOpenDynaset from the code and it works perfect. How important
is
that little bit of code and is it needed? Note:both "SQL =" lines are
typed
on the same line

Private Sub Form_AfterInsert()
If Me.SupplyPartCategory = "Window" Then
Dim SQL As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
SQL = "SELECT Model_ID, SupplyPart_ID FROM qryWWindowsXREFModels WHERE
qryWWindowsXREFModels.Model_ID = " & Me.Model_ID & " AND
qryWWindowsXREFModels.SupplyPart_ID = " & Me.SupplyPart_ID & ";"
'Set rst = db.OpenRecordSet(SQL, dbOpenDynaset)
Set rst = db.OpenRecordset(SQL)
If rst.RecordCount = 0 Then
SQL = "INSERT INTO qryWWindowsXREFModels (Model_ID, SupplyPart_ID)
VALUES (" & Me.Model_ID & ", " & Me.SupplyPart_ID & ")"
DoCmd.RunSQL SQL
Me.Parent.[subFrmWQryWindows(New)].Form.Requery
End If
End If
End Sub

"JKarchner" wrote:

sorry the code is actually supposed to be:
Set rst = db.OpenRecordSet(SQL, dbOpenDynset)

but it still doesnt work

"JKarchner" wrote:

thank you, that solved that problem. however i am getting the same
error in
a different location now. the error now occurs on line:

Set rst = db.OpenRecordSet(SQL, dbOpenDynset)

any help you can provide would be great. thank you

"ruralguy via AccessMonster.com" wrote:

While looking at your code go to Tools>References... and scroll down
to
Microsoft DAO 3.x Object Library and put a check in it.

JKarchner wrote:
I found this code online and modified to work with my database.
However i
get an error saying: "Can't find project or library" on the first
line with
DAO in it. My code is below, can anyone help me?

Private Sub Form_AfterInsert()
If Me.SupplyPartCategory = "Window" Then
Dim SQL As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strQuote As String
strQuote = Chr$(34)
Set db = CurrentDb()
SQL = "SELECT Model_ID, SupplyPart_ID" _
& "FROM qryWWindowsXREFModels" _
& "WHERE qryWWindowsXREFModels.Model_ID =" _
& strQuote & Me.Model_ID & strQuote _
& "AND qryWWindowsXREFModels.SupplyPart_ID =" _
& strQuote & Me.SupplyPart_ID & strQuote & ";"
Set rst = db.OpenRecordSet(SQL, dbOpenDynset)
If rst.RecordCount = 0 Then
SQL = "INSERT INTO qryWWindowsXREFModels (Model_ID,
SupplyPart_ID)
VALUES (" & Me.Model_ID & ", " & Me.SupplyPart_ID & ")"
DoCmd.RunSQL SQL
Me.Parent.[subFrmWQryWindows(New)].Form.Requery
End If
End If
End Sub

Thank you for any help you can provide.

--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200610/1




.



Relevant Pages

  • Re: variables and parameters
    ... Do I need to define it in the "Dim" section? ... Dim strTo As String ... Dim sql As String ... Set rst = db.OpenRecordset ...
    (microsoft.public.access.formscoding)
  • Re: Too few parameters
    ... value of the date into the SQL. ... > a query is run through Access ... > Dim db As DAO.Database ... > Set rst = qdf.OpenRecordset ...
    (microsoft.public.access.queries)
  • RE: On Form_Load() check if select query is null
    ... Why do you think something is wrong with the SQL? ... Dim rst As DAO.Recordset ... Set rst = db.OpenRecordset("SELECT ALLPolicies.CustomerNo, ...
    (microsoft.public.access.formscoding)
  • Re: Problem using DAO
    ... Set rst = db.OpenRecordSet(SQL, dbOpenDynset) ... Dim SQL As String ... Dim db As DAO.Database ...
    (microsoft.public.access.formscoding)
  • SQL.REQUEST #N/A error
    ... Dim RST As ADODB.Recordset ... Dim SQL As String ... Set RST = New ADODB.Recordset ... Microsoft Excel MVP ...
    (microsoft.public.excel.programming)