Hello all! I have a question about ADO, as I am entirely new to it and want to be able to utilize it in my database (I would like to eventually get rid of linked tables, but at this point I feel like I am dreaming! Hehe!). I am currently using DAO, and seem to have a hold on it, and have coded my first ADO procedure, but I need a little clarification on something. First off, here is my code:
What I need to know is, is there a way to just set the recordsource of the form to the ensuing recordset I get from ADO, instead of having to fill each field manually, like I do in this section:
Sorry for the long post, and thanks in advance for any help!
Code:
Private Sub Form_Load()
On Error GoTo HandleErrors
Dim snSQL As String
'open connection to QC database
Set adSerialConn = New ADODB.Connection
adSerialConn.Open "Provider='Microsoft.JET.OLEDB.4.0';" & _
"Data Source='T:\Quality Database\SerialNumber.mdb'"
'build the recordsource for the macola info subform
snSQL = "SELECT SERIALNO.SERIAL_NO, SERIALNO.SUBASSY, SERIALNO.DATE, SERIALNO.CUST_NAME, SERIALNO.SHIPDATE" & _
" FROM SERIALNO " & _
"WHERE SERIALNO.SERIAL_NO = " & Nz(Forms![Serial Number Manual Update Form]![Serial Number], "") & ";"
'apply the recordsource
Set adSerialRS = New ADODB.Recordset
adSerialRS.Open snSQL, adSerialConn, adOpenDynamic, adLockReadOnly
With adSerialRS
Me.SERIAL_NO.SetFocus
Me.SERIAL_NO.Text = Nz(.Fields("SERIAL_NO"), "")
Me.Date.SetFocus
Me.Date.Text = Nz(.Fields("DATE"), "")
Me.SUBASSY.SetFocus
Me.SUBASSY.Text = Nz(.Fields("SUBASSY"), "")
Me.CUST_NAME.SetFocus
Me.CUST_NAME.Text = Nz(.Fields("CUST_NAME"), "")
Me.SHIPDATE.SetFocus
Me.SHIPDATE.Text = Nz(.Fields("SHIPDATE"), "")
Forms![Serial Number Manual Update Form]![Serial Number].SetFocus
End With
err_exit:
Exit Sub
HandleErrors:
Me.CUST_NAME.SetFocus
Me.CUST_NAME.Text = "No Matching Records."
Resume err_exit
End Sub
Code:
With adSerialRS
Me.SERIAL_NO.SetFocus
Me.SERIAL_NO.Text = Nz(.Fields("SERIAL_NO"), "")
Me.Date.SetFocus
Me.Date.Text = Nz(.Fields("DATE"), "")
Me.SUBASSY.SetFocus
Me.SUBASSY.Text = Nz(.Fields("SUBASSY"), "")
Me.CUST_NAME.SetFocus
Me.CUST_NAME.Text = Nz(.Fields("CUST_NAME"), "")
Me.SHIPDATE.SetFocus
Me.SHIPDATE.Text = Nz(.Fields("SHIPDATE"), "")
Forms![Serial Number Manual Update Form]![Serial Number].SetFocus
End With