D
Dan
Hello
I have a serious problem
I have Command table with these fields: CommandID:
Autonumber and CommandNumber: C+Year+Month+CommandID
When I add my command to the DB I use this code:
Set rstCommande = New ADODB.Recordset
rstCommande.CursorType = adOpenKeyset
rstCommande.LockType = adLockOptimistic
rstCommande.Open "Tb_Command", cnn1, , , adCmdTable
rstCommande.AddNew
rstCommande!Description = "Import File to DB"
rstCommande!CommandeDate = Date
rstCommande!ClientID = 2
rstCommande.Update
but I still have the CommandNumber to add:
So I use this code:
sqlCommand = "SELECT Tb_Command.CommandID, Max(CommandID)
AS MaxCommandID FROM Tb_Command"
Set rsCommandID = dbs.OpenRecordset(sqlCommand)
iCommandID = rsCommandID![MaxCommandID] + 1
sNumCommand = "C" & Year(Date) & Month(Date) & iCommandID
rstCommand!NumberCommand = sNumCommand
rstCommand.Update
rstCommand.Close
But the error is in this line: iCommandID = rsCommandID!
[MaxCommandID] + 1, for the first record I add to the
table Tb_Command, it's not able to read MaxCommandID,
it's giving Null Always, I tried to copy and Paste my
query into the Query Generator, and the result is the
last CommandID, no NULL value
Any suggestions please
I have a serious problem
I have Command table with these fields: CommandID:
Autonumber and CommandNumber: C+Year+Month+CommandID
When I add my command to the DB I use this code:
Set rstCommande = New ADODB.Recordset
rstCommande.CursorType = adOpenKeyset
rstCommande.LockType = adLockOptimistic
rstCommande.Open "Tb_Command", cnn1, , , adCmdTable
rstCommande.AddNew
rstCommande!Description = "Import File to DB"
rstCommande!CommandeDate = Date
rstCommande!ClientID = 2
rstCommande.Update
but I still have the CommandNumber to add:
So I use this code:
sqlCommand = "SELECT Tb_Command.CommandID, Max(CommandID)
AS MaxCommandID FROM Tb_Command"
Set rsCommandID = dbs.OpenRecordset(sqlCommand)
iCommandID = rsCommandID![MaxCommandID] + 1
sNumCommand = "C" & Year(Date) & Month(Date) & iCommandID
rstCommand!NumberCommand = sNumCommand
rstCommand.Update
rstCommand.Close
But the error is in this line: iCommandID = rsCommandID!
[MaxCommandID] + 1, for the first record I add to the
table Tb_Command, it's not able to read MaxCommandID,
it's giving Null Always, I tried to copy and Paste my
query into the Query Generator, and the result is the
last CommandID, no NULL value
Any suggestions please