Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a record set

Status
Not open for further replies.

progressive

Technical User
Jun 6, 2001
6
GB
hello all,

could anyone explain what is wrong in the following code:
when i attempt to open the recordset is produces the error type mismatch. however i can't see why this would be a problem becasue rs is set as a recordset and tblapplicationdetails is a table.

thanks


Private Sub Command33_Click()
Dim rs As Recordset, _
sql As String, _
nSCR As Long, _
nSRF As Long

On Error GoTo Error
'//Discover SCR and SRF numbers from form values;
nSCR = Me.RecordID 'scr number comes from this form - the UID label;
nSRF = Forms!frmtblApplicationDetails.ApplicationID 'srf number comes from open instance of SRF form;


'//Open SRF-SCR linking tables;
Set rs = CurrentDb.OpenRecordset("tblapplicationdetails")


'//Insert srf and scr numbers into new record;
With rs
.AddNew 'add new record
!RecordID = nSCR 'set field value
!ApplicationID = nSRF 'set field value
.Update 'confirm update
End With
Exit Sub
Error:
Debug.Print "Form1.Command8_Click: " & Err.Description
MsgBox ("Form1.Command8_Click: " & Err.Description)
End Sub
 
Try adding this:

Dim db as Database
Set db = Currentdb()

I think you just forgot...
 
Hi!

You shouldn't need to set a database object in this case. Are you by any chance using A2k? If you are then you will need to go to the code window and select Tools from the menubar. Click on references and find the reference to DAO 3.6 object library. Check the reference and then use the arrow keys to move the reference up until it is above the reference to the ADO object library. If you don't want to move the reference up, then you can explicitly declare the recordset:

Dim rst As DAO.Recordset

ADO doesn't recognize the CurrentDb function.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top