Add a new record using VB

J

jon

Hi All
I am trying to add a record to a table from information on a form.

The Table is called SRSValue
The form is called Form_SRS_Input

The 2 field on the form I want to save are called.

SRSValue
FrmCount_Temp

And I want to save them to the fields

SRS_Val
LinkToTemp

The code I have now is messed up with me trying and failing to get it to
work ( but it is below).

Thanks
Jon


Private Sub ButSrsAdd_Click()
On Error GoTo Err_ButSrsAdd_Click

Dim db As Database
Dim rst As Recordset

Set db = CurrentDb()

rst.Open "srs_input", , , , ' *** don't know what to put here***
With rst
.AddNew

[SRSValue]![LinktoTemp] = Me![FrmCount_Temp]
[SRSValue]![SRS_Val] = Me![SRSValue]
.Update
.Close


End With


Exit_ButSrsAdd_Click:
Exit Sub

Err_ButSrsAdd_Click:
MsgBox Err.Description
Resume Exit_ButSrsAdd_Click

End Sub
 
V

Vladimír Cvajniga

Private Sub ButSrsAdd_Click()
Dim rst As Recordset

On Error GoTo Err_ButSrsAdd_Click

Set rst = CurrentDb.OpenRecordset("SRSValue")
With rst
.AddNew
!LinktoTemp = Me![FrmCount_Temp]
!SRS_Val = Me![SRSValue]
.Update
.Close
End With

rst.Close
Set rst = Nothing

Exit_ButSrsAdd_Click:
Exit Sub

Err_ButSrsAdd_Click:
MsgBox Err.Description
Resume Exit_ButSrsAdd_Click

End Sub
 
J

jon

Thanks Vlado
Working just right now Thanks
but I did have to REM out the line rst.close
Is that because it had already closed the rst within in the with statement?

Regards

Jon

Vladimír Cvajniga said:
Private Sub ButSrsAdd_Click()
Dim rst As Recordset

On Error GoTo Err_ButSrsAdd_Click

Set rst = CurrentDb.OpenRecordset("SRSValue")
With rst
.AddNew
!LinktoTemp = Me![FrmCount_Temp]
!SRS_Val = Me![SRSValue]
.Update
.Close
End With

rst.Close
Set rst = Nothing

Exit_ButSrsAdd_Click:
Exit Sub

Err_ButSrsAdd_Click:
MsgBox Err.Description
Resume Exit_ButSrsAdd_Click

End Sub
---------------------------------------------------
HTWOK (Hope this works OK)
HTH

Vlado

jon said:
Hi All
I am trying to add a record to a table from information on a form.

The Table is called SRSValue
The form is called Form_SRS_Input

The 2 field on the form I want to save are called.

SRSValue
FrmCount_Temp

And I want to save them to the fields

SRS_Val
LinkToTemp

The code I have now is messed up with me trying and failing to get it to
work ( but it is below).

Thanks
Jon


Private Sub ButSrsAdd_Click()
On Error GoTo Err_ButSrsAdd_Click

Dim db As Database
Dim rst As Recordset

Set db = CurrentDb()

rst.Open "srs_input", , , , ' *** don't know what to put here***
With rst
.AddNew

[SRSValue]![LinktoTemp] = Me![FrmCount_Temp]
[SRSValue]![SRS_Val] = Me![SRSValue]
.Update
.Close


End With


Exit_ButSrsAdd_Click:
Exit Sub

Err_ButSrsAdd_Click:
MsgBox Err.Description
Resume Exit_ButSrsAdd_Click

End Sub
 
V

Vladimír Cvajniga

Yes, it was a mistake, sorry.

jon said:
Thanks Vlado
Working just right now Thanks
but I did have to REM out the line rst.close
Is that because it had already closed the rst within in the with
statement?

Regards

Jon

Vladimír Cvajniga said:
Private Sub ButSrsAdd_Click()
Dim rst As Recordset

On Error GoTo Err_ButSrsAdd_Click

Set rst = CurrentDb.OpenRecordset("SRSValue")
With rst
.AddNew
!LinktoTemp = Me![FrmCount_Temp]
!SRS_Val = Me![SRSValue]
.Update
.Close
End With

rst.Close
Set rst = Nothing

Exit_ButSrsAdd_Click:
Exit Sub

Err_ButSrsAdd_Click:
MsgBox Err.Description
Resume Exit_ButSrsAdd_Click

End Sub
---------------------------------------------------
HTWOK (Hope this works OK)
HTH

Vlado

jon said:
Hi All
I am trying to add a record to a table from information on a form.

The Table is called SRSValue
The form is called Form_SRS_Input

The 2 field on the form I want to save are called.

SRSValue
FrmCount_Temp

And I want to save them to the fields

SRS_Val
LinkToTemp

The code I have now is messed up with me trying and failing to get it to
work ( but it is below).

Thanks
Jon


Private Sub ButSrsAdd_Click()
On Error GoTo Err_ButSrsAdd_Click

Dim db As Database
Dim rst As Recordset

Set db = CurrentDb()

rst.Open "srs_input", , , , ' *** don't know what to put here***
With rst
.AddNew

[SRSValue]![LinktoTemp] = Me![FrmCount_Temp]
[SRSValue]![SRS_Val] = Me![SRSValue]
.Update
.Close


End With


Exit_ButSrsAdd_Click:
Exit Sub

Err_ButSrsAdd_Click:
MsgBox Err.Description
Resume Exit_ButSrsAdd_Click

End Sub
 

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