Open Record

M

Martin

Hello,

I am trying to update a specific record from soem unbound fields in a form.
Here is the code from the button to update the record:

Private Sub Update_Click()
Dim dbs As Database, rs As Recordset

Set dbs = CurrentDb

Set rs = dbs.OpenRecordset("QryStaffHours", dbOpenSnapshot)
rs.Edit
rs![Jan '08 (a/l)] = Me![Jan4].Value
rs![Feb '08 (a/l)] = Me![Feb4].Value
rs![Mar '08 (a/l)] = Me![Mar4].Value
rs![Apr '08 (a/l)] = Me![Apr4].Value
rs![May '08 (a/l)] = Me![May4].Value
rs![Jun '08 (a/l)] = Me![Jun4].Value
rs![Jul '08 (a/l)] = Me![Jul4].Value
rs![Aug '08 (a/l)] = Me![Aug4].Value
rs![Sep '08 (a/l)] = Me![Sep4].Value
rs![Oct '08 (a/l)] = Me![Oct4].Value
rs![Nov '08 (a/l)] = Me![Nov4].Value
rs![Dec '08 (a/l)] = Me![Dec4].Value
rs.Update

End Sub

The qyuery called "QryStaffHours" works perfectly and is updatable. I am
fairly new to VBA so am trying to peice this together from what i know but I
think I am having trouble with the dbOpen part. Can anyone help please?

Thank you.

Martin
 
B

Bernie

try this one:

Public Function AddRecordReferentialIntegrity(strmainform, strRecordsource,
strRecordsource2, fieldname)

Set db = DBEngine(0)(0)
Dim rs As Recordset
Dim rs1 As Recordset
Dim rs2 As Recordset
Dim sql As String
Dim sql2 As String

Dim tempCounter As Long
Dim f As Form
Set f = Screen.ActiveForm

sql = "Select * from " & strRecordsource & ";"
sql2 = "Select * from " & strRecordsource2 & ";"
Set rs = db.OpenRecordset(sql, DB_OPEN_DYNASET, DB_APPENDONLY)
Set rs2 = db.OpenRecordset(sql, DB_OPEN_DYNASET, DB_READONLY)

Set rs1 = rs.Clone()
rs2.MoveFirst


MsgBox ("sql from AddRecord: " & sql)
rs.AddNew
rs!tabPartsID = rs2!tabPartsID
rs.Update

rs1.Bookmark = rs.LastModified
'rs1.LastModified
'F.Form.RecordSource = (strRecordsource)
'F.Form.Recordset = rs1

Set Forms(strmainform).Recordset = rs1

Call bind(strmainform)

MsgBox ("please check new entry")

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top