Hi
Here is my problem - I am trying to assign record values within a query (only about 30 records) to an array in order to automatically insert a debit note number. Currently I have a list of suppliers that I am going to raise debit notes on each month, and each debit note for each supplier will have a different (sequential debit note number). I want to use the supplier code as the identifier in order to get Access to look at another table and insert debit note numbers accordingly. The number will apply to more than one record in another table, so an autonumber is not viable. In addition, the debit note numbers were at about 1100 when I transferred my system into Access. Here is the code in my module so far:
I've also tried putting the query into a form and trying to do it that way, but it doesn't work. If anyone can help, I would be most grateful.
Here is my problem - I am trying to assign record values within a query (only about 30 records) to an array in order to automatically insert a debit note number. Currently I have a list of suppliers that I am going to raise debit notes on each month, and each debit note for each supplier will have a different (sequential debit note number). I want to use the supplier code as the identifier in order to get Access to look at another table and insert debit note numbers accordingly. The number will apply to more than one record in another table, so an autonumber is not viable. In addition, the debit note numbers were at about 1100 when I transferred my system into Access. Here is the code in my module so far:
Code:
Sub InsertDebitNoteNumbers()
Dim SupCode$()
Dim objField As Field
Dim CurrentRecord As AcRecord
LastDNNumber = DMax("[Debit Note Number]", "NCR/Debit Note Log")
TotaltoDebit = DCount("[Total Cost (Local Currency)]", "Companies to be debited", "abs([Total Cost (Local Currency)])>0")
DoCmd.OpenQuery "Companies to be debited", , acEdit
Application.Echo True
For SCode = 1 To TotaltoDebit
DoCmd.GoToRecord acDataQuery, "Companies to be debited", acGoTo, SCode
' This is where I need help - I want to assign a value to SupCode$(SCode), which should be the record that Access is currently on, as selected above.
Next SCode
DoCmd.Close acQuery, "Companies to be debited", acSaveNo
DoCmd.OpenTable "test", acViewNormal, acEdit
DoCmd.RunCommand acCmdApplyFilterSort
DoCmd.Close acTable, "test", acSaveYes
DoCmd.OpenTable "test", acViewNormal, acEdit
SCode = 1
For DNNumber = LastDNNumber + 1 To LastDNNumber + TotaltoDebit
' This code will insert the debit note number into the required field (Code not written yet, but this should be straightforward).
Next DNNumber
DoCmd.Close acTable, "test", acSaveNo
End Sub
I've also tried putting the query into a form and trying to do it that way, but it doesn't work. If anyone can help, I would be most grateful.