Runtime Error 438 when copying similar record

james_IT

Registered User.
Local time
Today, 19:46
Joined
Jul 5, 2006
Messages
208
Hi guys

With some help i had previously been able to make a button on my form that copied that record to a new record (depending on which check boxes were ticked).

It all worked ok but after some more work on the database im getting a runtime error 438 when trying to run the command button.

I have check all the controls and made sure there is a chk tick box for each one. Dont know what else to try.

Thanks

Code:
Private Sub cmdfill_Click()
Dim strSQL As String

strSQL = "SELECT * FROM tblTicketing WHERE StockNumber = '" & Me.StockNumber & "'"
  DoCmd.GoToRecord acDataForm, Me.Name, acNewRec

Dim c As Control
  Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)

    Me.Painting = False

      For Each c In Me.Controls
        If Not TypeOf c Is CheckBox Then
          If Not TypeOf c Is Label Then
            If Not TypeOf c Is CommandButton Then
              If Me.Controls("chk" & c.Name) = -1 Then
                Debug.Print c.Name
                c = rs(c.ControlSource)
              End If
            End If
          End If
        End If
      Next c
   
    Me.Painting = True

  rs.Close

Set rs = Nothing

End Sub
 
Last edited:
The parts in red are contradictory. You should never get to the second red part.
Code:
      For Each c In Me.Controls
        [COLOR="Red"]If Not TypeOf c Is CheckBox Then[/COLOR]
          If Not TypeOf c Is Label Then
            If Not TypeOf c Is CommandButton Then
              [COLOR="red"]If Me.Controls("chk" & c.Name) = -1 Then[/COLOR]
                Debug.Print c.Name
                c = rs(c.ControlSource)
              End If
            End If
          End If
        End If

But I'm betting that your major problem is here:

c = rs(c.ControlSource)

You can't set c equal to something. It already is a control. What is it you really want there? I can't really tell to tell you the truth.
 
The parts in red are contradictory. You should never get to the second red part.
Code:
      For Each c In Me.Controls
        [COLOR="Red"]If Not TypeOf c Is CheckBox Then[/COLOR]
          If Not TypeOf c Is Label Then
            If Not TypeOf c Is CommandButton Then
              [COLOR="red"]If Me.Controls("chk" & c.Name) = -1 Then[/COLOR]
                Debug.Print c.Name
                c = rs(c.ControlSource)
              End If
            End If
          End If
        End If

But I'm betting that your major problem is here:

c = rs(c.ControlSource)

You can't set c equal to something. It already is a control. What is it you really want there? I can't really tell to tell you the truth.

Thanks for the comments.

I got the code from a sample database that had a similar function so Im not too sure what it should be! :(

Yes, that is the line that comes up highlighted when I click debug. Any ideas on what I could try?

Thanks again
 
Thanks for the comments.

I got the code from a sample database that had a similar function so Im not too sure what it should be! :(

Yes, that is the line that comes up highlighted when I click debug. Any ideas on what I could try?

Thanks again
Well, again I have to ask you - what do you THINK it does? Or, what do you really want to happen? Ignore what the code says for now. What is it you really want to happen as that will determine what code you use.
 
Well, again I have to ask you - what do you THINK it does? Or, what do you really want to happen? Ignore what the code says for now. What is it you really want to happen as that will determine what code you use.

I want it to take the the values from the fields that have associated tick boxes set to true onto a new record.

I got the sample database which I previously had got working from this thread.

Please see for more info: http://www.access-programmers.co.uk/forums/showthread.php?t=185144&page=2

Thanks again
 
Everything else works behind the error box (and if I press debug, close) so couldnt i just add "on error resume next"?
 

Users who are viewing this thread

Back
Top Bottom