Full Version: Help Me Stop Overwriting Controls On My Datasheet Form!
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
DaveMarvin
Hi all:

I'm using a dynamic pass-through query in Access 2010 to retrieve one or more records from a back-end database. After much trial and error, I plagiarized enough of the right code to retrieve the appropriate records and assign them to unbound text-boxes on my datasheet form during an OnLoad event. The only problem remaining is in displaying multiple records. I've verified that I AM retrieving multiple records, but the contents of each record's fields overwrite the previous values stored to the form's textbox controls, so I always end up with just a single record displayed in my datasheet when I expect to see anywhere from one to 10.

I'm sure it's a simple solution. Can someone please point it out to me?

CODE
Private Sub Form_Load()
    Dim sqlString As String
    sqlString = "SELECT Transmitter_ID, Receiver_ID, UTC_Date, Local_Date from Detections"
    If Not IsNull(Me.OpenArgs) Then
        sqlString = sqlString & " where " & OpenArgs
    End If

    Dim cnn As New ADODB.Connection
    Dim cmd As New ADODB.Command
    Dim rst As ADODB.Recordset

    'Define and open connection
    cnn.ConnectionString = "DRIVER={SQLite3 ODBC Driver};Database=z:\EWAMP\EWAMP_be_dev.sqlite"
    cnn.Open

    'Define ADO command
    cmd.ActiveConnection = cnn
    cmd.CommandText = sqlString

    'Populate and enumerate through recordset
    Set rst = cmd.Execute
    If rst.EOF Then
       MsgBox "Nothing found...", vbInformation + vbOKOnly
       Exit Sub
    Else
        Do While Not rst.EOF
            '// I'm guessing the problem is with my control assignments, here.
            Me.cntl_Receiver_ID.Value = rst("Receiver_ID")
            Me.cntl_Transmitter_ID.Value = rst("Transmitter_ID")
            Me.cntl_UTC_Date.Value = rst("UTC_Date")
            Me.cntl_Local_Date.Value = rst("Local_Date")
            Debug.Print {Show me the four control values}
            rst.MoveNext
        Loop
    End If

End Sub


Cheers!
DUHdley
missinglinq
An Unbound Form in reality contains No Records, and hence cannot display Multiple Records. The Controls merely hold data that can be written to Fields in a Table, creating a Record.

To show Multiple Records, in a Form, they must first reside in a Table. It can be a temporary Table, but it must be a Table.

One approach would be create a temporary Table using a Make Table Query.

Linq ;0)>
MadPiet
just wondering... can you bind a form to an ADO recordset? In this situation, that seems like it would be ideal. Then maybe you could commit the changes using .UpdateBatch, right?
MadPiet
If you wanted to add records to the table using an unbound form, it would be something like this:


rst.AddNew
rst("Receiver_ID")=Me.cntl_Receiver_ID.Value
rst("Transmitter_ID")=Me.cntl_Transmitter_ID.Value
rst("UTC_Date")=Me.cntl_UTC_Date.Value
rst("Local_Date")=Me.cntl_Local_Date.Value
rst.Update
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.