General information
Category:
Coding, syntax & commands
ok... I realize the numbers continue from where the last increment was. So, what do I do given the following...
(Now I typically develop with VFP and have plenty of experience with SQL-Insert, Update, Delete, etc but VB/Access has some twists I'm not used to...)
Ok.. Table structure
MyTable
Tbl1Key autonumber
Descrip text
I already have (via normal view mode and adding records) Key 1, 2, 3 with respective descriptions... Now, in code from a button on a form, I want to add a new description by some other means... All I want to do is add the description and let the auto-numbering kick in for the primary key column so...
insert into MyTable ( Descrip ) values ( 'Some text string' )
And based on J. Flores input, I also had to acitvate this via a DoCmd call... So, in the "CLICK" event of the button I have
Sub MyCommandButton_Click()
DoCmd.RunSQL( "insert into MyTable ( Descrip ) values ( 'Some text string'
" )
End Sub
This fails with an error due to duplicate key (and the Descrip column is not indexed, nor requires uniqueness -- just to remove possibilities of duplicate descriptions IS NOT the case).
Do I need to "pre-SQL" a call for the max( Tbl1Key ) to a variable, then add 1 to that and add to the Insert call? If so, How would I do that in VB... Yeah, I can issue a SQL statement to get that, but how to put directly to a variable. This is quite easy using Visual Foxpro as I would do something like...
dimension laMyAnswer[1]
select max( Tbl1Key ) from MyTable into array laMyAnswer
that's it... I have my query into a local variable for me to play with... How would I do an equivalent via VB
Thanks
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only