Results 1 to 4 of 4
  1. #1
    Rider570 is offline Novice
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    2

    runtime error 3219

    Code:
    NSQL = "INSERT INTO tblOpeName (name)" & " values (" & MSQL & ")"
    Error occurs here.
    What i need to do is
    1. Copy Unique Operator name(No duplicates) (OpeName1) from tblGage
    2. Where Date equal to txtdate.text
    3. Insert them into another field called Name in tblOpeName
    Until this line prg works well.
    Code:
    OSQL = "SELECT DISTINCT OpeName1 FROM tblGage WHERE Date =" & SQLDate(txtdate.Text)
    Set rss = dbs.OpenRecordset(OSQL)
    MSQL = rss("OpeName1")
    sqldate funtion will return txtdate.text as #txtdate.text # where suitable to sql.

    OSQL vale looks like "Text"

    Plz help to solve this
    Thanx



    Code:
    Private Sub cmdsummery_Click()
    Set wss = DBEngine.Workspaces(0)
    Set dbs = wss.OpenDatabase("Gagedetails.mdb")
    Set rss = dbs.OpenRecordset("tblGage")
     
    Do While Not rss.EOF
    OSQL = "SELECT DISTINCT OpeName1 FROM tblGage WHERE Date =" & SQLDate(txtdate.Text)
    Set rss = dbs.OpenRecordset(OSQL)
    MSQL = rss("OpeName1")
    NSQL = "INSERT INTO tblOpeName (name)" & " values (" & MSQL & ")"
    Set rss = dbs.OpenRecordset(NSQL)
    rss.MoveNext
    Loop
    rss.Close
    Set rss = Nothing
    End Sub
    When i tried to run this got a Error code "runtime error 3219"
    plz help

  2. #2
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    The first issue I see is that the field "name", the word name is a reserved word in Access. It is best not to use reserved words, so I would suggest changing the field name to perhaps txtOperName; in the mean time you can try enclosing the field name in square brackets. Additionally, you need to set off a text field with single quotes


    Now regarding the VALUES section of the SQL text, if the following query can return multiple distinct openames, the way you have your append query will at most append 1. You need to loop through the recordset and append each opeName (you don't have the loop in the right place in your code)

    "SELECT DISTINCT OpeName1 FROM tblGage WHERE Date =" & SQLDate(txtdate.Text)

    BTW, "date" is also a reserved word in ACCESS

    I assume that your SQLDate() function has been verified to give you the correct output. Where is txtdate.Text getting it's value? Is it a control on the same for as the command but that runs this code? If so, you can reference it as me.txtDate (assuming that the control name is txtDate).

    Here is what I think the code should look like (not tested)

    Code:
    Private Sub cmdsummery_Click()
    Set wss = DBEngine.Workspaces(0)
    Set dbs = wss.OpenDatabase("Gagedetails.mdb")
    
    OSQL = "SELECT DISTINCT OpeName1 FROM tblGage WHERE [Date] =" & SQLDate(txtdate.Text)
    Set rss = dbs.OpenRecordset(OSQL) 
    Do Until rss.EOF
    
    NSQL = "INSERT INTO tblOpeName ([name])" & " values ('" & rss!OpeName1 & "')"
    
     CurrentDb.Execute NSQL, dbFailOnError
     
    rss.MoveNext
    Loop
    rss.Close
    Set rss = Nothing
    End Sub

    On an outside note, you do not need code to do what you are trying to do. You can use a query along these lines:

    INSERT INTO tblOpeName ( [name] )
    SELECT DISTINCT tblGage.OpeName1
    FROM tblGage
    WHERE (((tblGage.[Date])=[forms]![YourFormName]![txtDate]));

  3. #3
    Rider570 is offline Novice
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    2

    Problem Solved

    Thank you very much for the help.
    Problem has solved.

  4. #4
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Great! I'm glad you got it worked out; good luck on your project.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Runtime Error '3027': Database or object is read only
    By 4x4Masters in forum Programming
    Replies: 4
    Last Post: 06-08-2010, 08:02 PM
  2. Replies: 3
    Last Post: 04-15-2010, 09:43 AM
  3. runtime error 2448
    By ds_8805 in forum Forms
    Replies: 3
    Last Post: 04-14-2010, 07:32 PM
  4. Help With Runtime Error 4248
    By KLahvic in forum Programming
    Replies: 1
    Last Post: 04-09-2010, 07:47 AM
  5. Runtime 3075 error
    By whm1 in forum Programming
    Replies: 4
    Last Post: 03-24-2010, 02:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums