Hi All,
I'm trying to code for a 'duplicate record' button on a form that, as well as copying the values of all the controls of the previous record to the new record, makes a certain control (which contains a number) increment as appropriate.
There are two controls on the form which contain the start and end values of a numerical sequence (of potentially any length) e.g. the range 48-82 shows 48 in text box boxREGSEQSTART and 82 in the text box boxREGSEQEND OR the single value 99 shows 99 in text box boxREGSEQSTART and text box boxREGSEQEND is empty. In a record, the value of boxREGSEQEND would always be higher than that of boxREGSEQSTART or would be blank.
The appropriate incrementing action would be:
After clicking 'Duplicate Record' button,
- If there is no value in boxREGSEQEND in the record being copied, then in the new duplicated record the value of boxREGSEQSTART should be 1 greater than the value of boxREGSEQSTART in the record it has been copied from.
- i.e. the record being copied is records a single item, a single value, and the next record should show the sequence moved on by one
OR
- If there is a value in boxREGSEQEND in the record being copied, then in the new duplicated record the value of boxREGSTART should be 1 greater than the value of boxREGSEQEND in the record it has been copied from.
- i.e. the record being copied is recording multiple items, a sequence, but the next record should still show the sequence moved on by one
I can get the duplication to work no problem, and I can get the incrementing to work fine for the first set of conditions, but can't for the life of me get it to increment when there is a range!
The logic (in my head, expressed as best I can in the macro language
) for the whole sequence of actions goes like so:
RunMenuCommandCommand SelectRecord
RunMenuCommandCommand Copy
RunMenuCommandRecordsGoToNew
RunMenuCommandCommand SelectRecord
RunMenuCommandCommand Paste
If [boxREGSEQEND]=[IsNull] Then
GoToControlControl Name boxREGSEQSTART
SetValue
Item = [boxREGSEQSTART]
Expression = [boxREGSEQSTART]+1
Else
GoToControlControl Name boxREGSEQSTART
SetValue
Item = [boxREGSEQSTART]
Expression = [boxREGSEQEND]+1
GoToControlControl Name boxREGSEQEND
SetValue
Item = [boxREGSEQEND]
Expression = [boxREGSEQEND]=Null
Which I would assume would tell the program to copy the current record, make a new one and paste the copy, then if there was a range recorded in the original, start the numbering of the new record one number higher than the end of that range and clear the way in the new form in case it also records a range, otherwise just increment the sequence along by one.
As you can tell, I was working in macros rather than VB (mostly as a learning exercise), but would appreciate help in any macro or VB.
Oh, and apologies for explaining that in a million different ways!