iglobalusa
Registered User.
- Local time
- Today, 11:43
- Joined
- Jul 12, 2008
- Messages
- 30
I'm trying to pass a field value (Me.Record_No) from Form A (frmAddDetails) as an OpenArgs to Form B (frmAddTest). Me.Record_no is an AutoNumber field. The code works until Form B (frmAddTest) is opened, accepts the record_no in Me.OpenArgs and finds the record_no match in a table called labdata so I can populate frmAddTest with certain fields from the recordset ADO_RS created from the labdata table.
I get this error messsage on Form B (frmAddTest): "You can't assign a value to this object" when the code starts assigning values to frmAddTest from the labdata recordset.
Can someone tell me what I'm doing wrong?
Code from Form A (frmAddDetails)
Option Compare Database 'Use database order for string comparisons
Option Explicit
Dim strFormName As String
Private Sub cmdaddlabtest_Click()
On Error GoTo Err_cmdaddlabtest_Click
strFormName = "frmAddTest"
Code from Form B (frmAddTest) with additions allowed using acFormAdd when opening form
Option Compare Database 'Use database order for string comparisons
Option Explicit
Dim strFormName As String
Dim strSQL As String
Dim intrecord_no As Long
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
I get this error messsage on Form B (frmAddTest): "You can't assign a value to this object" when the code starts assigning values to frmAddTest from the labdata recordset.
Can someone tell me what I'm doing wrong?
Code from Form A (frmAddDetails)
Option Compare Database 'Use database order for string comparisons
Option Explicit
Dim strFormName As String
Private Sub cmdaddlabtest_Click()
On Error GoTo Err_cmdaddlabtest_Click
strFormName = "frmAddTest"
'pass record_no an autonumber field to frmAddTest as Openargs
If Not Me.NewRecord Then
Exit_cmdaddlabtest_Click:If Not Me.NewRecord Then
DoCmd.OpenForm strFormName, acNormal, , , acFormAdd, acWindowNormal, Me.record_no
End If
Exit Sub
Err_cmdaddlabtest_Click:
MsgBox Err.Description
Resume Exit_cmdaddlabtest_Click
End SubResume Exit_cmdaddlabtest_Click
Code from Form B (frmAddTest) with additions allowed using acFormAdd when opening form
Option Compare Database 'Use database order for string comparisons
Option Explicit
Dim strFormName As String
Dim strSQL As String
Dim intrecord_no As Long
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
'check openargs
If Not IsNull(Me.OpenArgs) Then
Exit_Form_Open:If Not IsNull(Me.OpenArgs) Then
intrecord_no = Me.OpenArgs
strSQL = "Select * from labdata Where record_no Like '" & intrecord_no & "'"
Set DAO_DB = CurrentDb()
Set DAO_RS = DAO_DB.OpenRecordset(strSQL, dbOpenDynaset)
With DAO_RS
'close recordset
DAO_RS.Close
Set DAO_RS = Nothing
End IfstrSQL = "Select * from labdata Where record_no Like '" & intrecord_no & "'"
Set DAO_DB = CurrentDb()
Set DAO_RS = DAO_DB.OpenRecordset(strSQL, dbOpenDynaset)
With DAO_RS
'Find the record_no in openargs
.FindFirst "[record_no] = " & intrecord_no
If DAO_RS.NoMatch Then
( I get the error after Else)
End With.FindFirst "[record_no] = " & intrecord_no
If DAO_RS.NoMatch Then
MsgBox "Record_no no match!"
Else
( I get the error after Else)
Me.stateno = DAO_RS("stateno")
Me.site_cd = DAO_RS("site_cd")
Me.l_name = DAO_RS("l_name")
Me.f_name = DAO_RS("f_name")
Me.m_name = DAO_RS("m_name")
Me.phone = DAO_RS("phone")
Me.ssn = DAO_RS("ssn")
Me.addr_1 = DAO_RS("addr_1")
Me.addr_2 = DAO_RS("addr_2")
Me.city = DAO_RS("city")
Me.cnty = DAO_RS("cnty")
Me.state = DAO_RS("state")
Me.zip_code = DAO_RS("zip_code")
Me.cntry = DAO_RS("cntry")
Me.birth_dt = DAO_RS("birth_dt")
Me.gender = DAO_RS("gender")
Me.lab_clia_no = DAO_RS("lab_clia_no")
Me.accession_no = DAO_RS("accession_no")
Me.medrecno = DAO_RS("medrecno")
Me.prison_no = DAO_RS("prison_no")
'refresh screen
Me.Refresh
End IfMe.site_cd = DAO_RS("site_cd")
Me.l_name = DAO_RS("l_name")
Me.f_name = DAO_RS("f_name")
Me.m_name = DAO_RS("m_name")
Me.phone = DAO_RS("phone")
Me.ssn = DAO_RS("ssn")
Me.addr_1 = DAO_RS("addr_1")
Me.addr_2 = DAO_RS("addr_2")
Me.city = DAO_RS("city")
Me.cnty = DAO_RS("cnty")
Me.state = DAO_RS("state")
Me.zip_code = DAO_RS("zip_code")
Me.cntry = DAO_RS("cntry")
Me.birth_dt = DAO_RS("birth_dt")
Me.gender = DAO_RS("gender")
Me.lab_clia_no = DAO_RS("lab_clia_no")
Me.accession_no = DAO_RS("accession_no")
Me.medrecno = DAO_RS("medrecno")
Me.prison_no = DAO_RS("prison_no")
'refresh screen
Me.Refresh
'close recordset
DAO_RS.Close
Set DAO_RS = Nothing
Exit Sub
Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open
End SubResume Exit_Form_Open
Last edited: