Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

autonumber on form from SQL Backend

Status
Not open for further replies.

MICKI0220

IS-IT--Management
Jul 20, 2004
337
0
0
US
I have a form that I input records. It doesn't allow me to save a record because it is not auto populating the field with the automatic number from the sql backend. When I open the form it opens on a new record. How do I get it to automatically assign the number so it will save a record?
 
Not sure what the cause is since it's linked to your table, but you might be best off just handling it via a SQL INSERT query.
Code:
Sub LastControl_AfterUpdate()
   Dim strSQL As String
   strSQL = "INSERT INTO MySqlTable (Field2, Field3, Field4, Field5) " & vbCrLf & _
            "SELECT '" & txtMyField2 & "' ,'" & txtMyField3 & "' ," & txtMyField4 & " ," & txtMyField5
   DoCmd.SetWarnings False
   DoCmd.RunSQL strSQL
   DoCmd.SetWarnings True
End Sub

I'm assuming that "Field1" would be your AutoNumber field, so you wouldn't need to include in an append/insert query. Now that's also assuming you have the table setup correctly with an Identity field.

'Course, if it is the case that your SQL table is not setup correctly, then it could be as simple as fixing that, and then you'll be all set.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top