Home » Category » Microsoft Visual Basic

Microsoft Visual Basic: Wrong AutoNummber (3-Tier)

112| Sat, 10 Nov 2007 02:32:00 GMT| eden| Comments (1)
Dear Ado-Experts,

I am using the following code to add Items to my Db,
'********
Public Function addItem(ByRef oItem As Item) As Boolean
Dim strSql As String
Dim tmpRs As Recordset

addMA_FB = False

strSql = "select * from Items"
Set tmpRs = New Recordset
If oDataLayer.GetConnectedRecordset(strSql, tmpRs, LT_Optimistic) Then 'Returns
filled tmpRs
With oItem
tmpRs.AddNew
tmpRs!Name = .Name
tmpRs!Art = .Art
tmpRs!Nr = .Nr
tmpRs.Update
tmpRs.Requery
tmpRs.MoveLast
--> .id = tmpRs!ITEM_ID ' here is the problem
End With
If oDatenZugriff.DisconnectRecordset(tmpRs) Then
'// okay
addItem = True
Set tmpRs = Nothing
End If
End If
End Function

MOveLast doesnt shift the cursor to the last data , so I keep
getting the wrong tmpRs!ITem_Id.
Does anyone have an idea how I could do it better ?
Thanx in advance!
Eden.

Keywords & Tags: wrong, autonummber, 3-tier, microsoft, visual basic, vb

URL: http://www.programmerbase.com/visual-basic/557782/
 
«« Prev - Next »» 1 helpful answers below.
Have a look at

http://www.able-consulting.com/ADO_Faq.htm#Q9

--

Andrew Grillage
http://www.concresco.com

Eden <Weldeab...cim-house.de> wrote in message
news:39096c1e$1...news.dev-archive.com...
>
> Dear Ado-Experts,
>
> I am using the following code to add Items to my Db,
> '********
> Public Function addItem(ByRef oItem As Item) As Boolean
> Dim strSql As String
> Dim tmpRs As Recordset
>
> addMA_FB = False
>
> strSql = "select * from Items"
> Set tmpRs = New Recordset
> If oDataLayer.GetConnectedRecordset(strSql, tmpRs, LT_Optimistic) Then
'Returns
> filled tmpRs
> With oItem
> tmpRs.AddNew
> tmpRs!Name = .Name
> tmpRs!Art = .Art
> tmpRs!Nr = .Nr
> tmpRs.Update
> tmpRs.Requery
> tmpRs.MoveLast
> --> .id = tmpRs!ITEM_ID ' here is the problem
> End With
> If oDatenZugriff.DisconnectRecordset(tmpRs) Then
> '// okay
> addItem = True
> Set tmpRs = Nothing
> End If
> End If
> End Function
>
> MOveLast doesnt shift the cursor to the last data , so I keep
> getting the wrong tmpRs!ITem_Id.
> Does anyone have an idea how I could do it better ?
> Thanx in advance!
> Eden.

andrewgrillage | Sun, 11 Nov 2007 19:56:00 GMT |

Microsoft Visual Basic Hot Answers

Microsoft Visual Basic New questions

Microsoft Visual Basic Related Categories