fisherbrsnch00
asked on
Setting field attributes to autoincrement
I am altering a database through code and everything is working fine except that I can't set a field to autoincrement
Here is what I've tried
- source_db.TableDefs(0).Fie lds(0).Att ributes = 17
and
- source_db.TableDefs(0).Fie lds(0).Att ributes = dbAutoIncrField
And both times I get the error:
"Run-time error '3219':"
"Invalid Operation"
MSDN says it should work, any idea?
Here is what I've tried
- source_db.TableDefs(0).Fie
and
- source_db.TableDefs(0).Fie
And both times I get the error:
"Run-time error '3219':"
"Invalid Operation"
MSDN says it should work, any idea?
ASKER
I'm not clear how that function would resolve the problem I'm having. Can you explain, or possibly show how this would work in vb?
Are u using DAO or ADO?
Sethi,
>>Are u using DAO or ADO?<<
What does it look like to you? Hint look up TableDefs in Google.
>>Are u using DAO or ADO?<<
What does it look like to you? Hint look up TableDefs in Google.
:-)) Stupid question from me. Thanks for the check.
Smart-ass response from me. I apologize.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That sounds good acperkins, but I'm wondering how I can use this method to alter an existing field? I suppose I could duplicate the field, make it autoincremented, copy the data over, kill the original and then rename the new field to the name of the original field... but that would seems like more work than is neccessary.
I simply want to take an existing field and make it autoincremented. Is this possible?
I simply want to take an existing field and make it autoincremented. Is this possible?
>>I suppose I could duplicate the field, make it autoincremented, copy the data over, kill the original and then rename the new field to the name of the original field... but that would seems like more work than is neccessary.<<
Yes, that is what you have to do and is exactly what MS Access (and MS SQL Server do, for that matter)
>>I simply want to take an existing field and make it autoincremented. Is this possible?<<
Nope. Which incidently was what ellandrd told you originally.
Yes, that is what you have to do and is exactly what MS Access (and MS SQL Server do, for that matter)
>>I simply want to take an existing field and make it autoincremented. Is this possible?<<
Nope. Which incidently was what ellandrd told you originally.
ASKER
I understand that I can not change it directly with the method I was using, but I was hoping there was an easy way around it... like using openschema, I just can't figure it out.
Anyway, if you can change all other properties for an existing table and field but not this one then so be it. I'll have to work around it.
Thanks.
Anyway, if you can change all other properties for an existing table and field but not this one then so be it. I'll have to work around it.
Thanks.
Public Sub ForceIdentifierToSetValue(
Dim rsData As DAO.Recordset
Dim lCounter As Long
lCounter = 1
Set rsData = CurrentDb.OpenRecordset(sT
Do While lCounter < lTargetNumber
rsData.AddNew
rsData.Update
rsData.MoveFirst
rsData.Delete
lCounter = lCounter + 1
Loop
End Sub
This must be called from within access, or modified to work from VB.