Need to Add and Delete records in subform

Thanks.
1, I like your elegant solution of the combo box for the job series title. Given the strange custom we have here of using the job series NUMBER almost exclusively, and that I'm adding the title as a courtesy, it's not in the requirements, I need to leave that as is for the moment.

2, I am implementing. Problem is that for a person with no tasks, Me!Version is null. Can DMAX be used to select the greater of "1" or [Version]? It doesn't look like it at the moment.

3) Now that I know, I am writing it up as an 'unadvertised Access feature' (the current euphemism for 'bug')

4) will tackle on Monday. I think I saw something for this, if I can remember where.
 
One problem left:

I implemented your code for Add Task, and made some changes.
It comes up with "Runtime error 2493, "this action requires an Object Name Argument" for
DoCmd.GoToRecord acDataForm, , acNewRec

This is most frustrating, as I know I have used this instruction before without problems.

I can skip the compute of PerfNo, as that is not strictly necessary. I MUST be able to store NameFull in the new record, as there is no place to enter that in the Task records, therefore I do need something that works under the Add Task button.
The "*" blank record doesn't work--it can't store name, and it comes up with syntax error when I try. Is it trying to put the PerfNo entry in some other field?

The code currently looks like this:
'add new task record
Dim strCrit As String ' hold criteria for the lookup
Dim intPerfNo As Integer 'holds PerfNo returned
Dim intVersion As Integer ' holds current version
Dim strNameFull As String 'holds name for transfer

intVersion = 1 'for 1st task of new person, [Version] is zero
If Me![Version] > intVersion Then intVersion = Me![Version]
strNameFull = [NameFull]
'due to technical problems, skipping the compute of PerfNo
'strCrit = "[NameFull] = ' " & Me!NameFull & " ' AND [Version] = " & intVersion
'intPerfNo = 0 ' for 1st task of new person, [PerfNo] doesn't exist yet
'Set to 0 because will be incremented by 1 later
'If [PerfNo] > 0 Then intPerfNo = [PerfNo] ' we have live PerfNo, get real number
DoCmd.GoToRecord acDataForm, , acNewRec
Me!NameFull = strNameFull ' Set name
'Me!PerfNo = intPerfNo + 1 'set new perf no, to 1 if new person
Me!Version = intVersion ' set the verson
Me!Active = -1 ' set Active = yes
Me.Requery

Thanks.
 
Take out the acDataForm
DoCmd.GoToRecord , , acNewRec

U may need to check for a null value first.
for example:
Code:
If NOT IsNull(me!Version) THEN
    intVersion = 1 'for 1st task of new person, [Version] is zero 
    If Me![Version] > intVersion Then intVersion = Me![Version] 
    ...
    Me!Active = -1 ' set Active = yes 
    Me.Requery
End if
 
Thanks. That DoCmd instruction change worked. btnAddTask now creates a new Task record just below itself, in 1st position.
Question: when do I use this form of DoCmd, and when the other?


Last (I hope) Technical problem:
Create a Task record for a new person.

There are 3 possibilities, all of which require a knowledge of indexing and access that I don't have.

1) Add code to btnAddPerson in frmPerson based on tblPerson that will add a blank task record to tblPerformance, requiring knowledge of how to add a record to a table other than the one I'm currently in.

2) Create a public variable, strNameFull, that can be loaded from by cboSelectName in frmPlan and can be accessed by btnAddTask in sfrmPlan. This is the preferred method, I think.

This did NOT work.
in frmPlan
Public Dim strNameFull

cboNameselect
strNameFull = [NameFull]

btnAddTask
Me!NameFull = strNameFull

3) from btnAddTask in sfrmPlan, grab the current contents of cboNameSelect in frmPlan if there is no task. This works if the problem is just a matter of how to code the line to access the variable, and the information is accessible
 
If u use acDataForm,
then u have to specify the name of the object as the next argument.
DoCmd.GoToRecord [objecttype, objectname][, record][, offset]
e.g. DoCmd.GoToRecord acDataForm, "frmPlan", acNewRec
I don't think i have ever used it like that. I guess if your trying to go to a new record in a subform, from a button in the main form, or on a different form altogether.


I'm not quite sure what your trying to do with the fullname. The sub form is linked via fullname so as soon as u enter something into the form, the fullname will be automatically saved into the table. Perhaps u could enter one of the other values on add task? Like version = 1 or something? But again, i'm not sure what you want.

Dave
 
The problem I'm trying to solve is that after I add a new person on frmPerson, and go to frmPlan and click on Add Task for this new person, I get "Runtime Error 94 Invalid Use of Null".

There is a workaround, putting data into the "*" record will add a new record almost correctly: Active is not set but NameFull is, but I'd rather do it 'right' from Add Task and eliminate the "*" record.
 
code currently looks like:
'add new task record
Dim strCrit As String ' hold criteria for the lookup
Dim intPerfNo As Integer 'holds PerfNo returned
Dim intVersion As Integer ' holds current version
Dim strNameFull As String ' holds name for new task

intVersion = 1 'for 1st task of new person, [Version] is zero
strNameFull = [NameFull] 'THIS IS THE NULL

If Not IsNull(Me!Version) Then ' version exists, not a new person
If Me![Version] > intVersion Then intVersion = Me![Version]
End If
'DoCmd.GoToRecord , , acNewRec
DoCmd.GoToRecord acDataForm, "frmPlan", acNewRec
Me!NameFull = strNameFull ' Copy name into new task record
Me!Version = intVersion ' set the verson
Me!Active = -1 ' set Active = yes
Me.Requery
 
Just comment out these two lines and see what happens:

strNameFull = [NameFull] 'THIS IS THE NULL
Me!NameFull = strNameFull ' Copy name into new task record

Like i said, there is no need to add namefull to the new record as it will do it automatically via the master/child links. It is still linked with namefull isn't it?
 
THANKS!
It worked perfectly, despite sfrmPlan being based on qryVersion with child link = version and master link = cboVersionSelect
 

Users who are viewing this thread

Back
Top Bottom