Opening record by ID opens a new record

dibblermail

Member
Local time
Today, 19:58
Joined
Jan 10, 2025
Messages
60
Sorry, me again.

This code was working a few days ago & upon testing it again today it isn't.

Yesterdays code was to fill in text boxes for a new record in this same form.

So I've broken something, or more likely, I need to be more specific to stop the code going off at a tangent.

The code I'm using is this...

Code:
DoCmd.OpenForm "form0_AddEditJob", , , "JobID=" & JobID

When I breakpoint the line & hover over JobID it has the correct job ID in it & this happens regardless of which Job ID I choose.

When it opens the form it's a new form. I have the JOB ID shown in the header of the form whilst I'm creating the database so I can see what it is pulling in. It shows (New) and the form is blank.

If I remove the filter showing at the bottom I'm able to scroll through the records correctly, so I assume it's the filter that's failing.

The form it's opening has a sub form. Is it getting confused as to which part of the form needs the data?

When the blank form opens the curser blinks a few times in a text box on the sub form as if it has focus.

Any thoughts on where I may be going wrong, or how I should hunt down the fix?

EDIT

Also, there's no error message.
 
So what did you change?
I would expect New for a new record?
Does the jobid record actually exist?
 
So what did you change?
I would expect New for a new record?
Does the jobid record actually exist?
Nothing that SHOULD affect this. It's being called from a different place & the code written yesterday is part of that call not this one & not part of the form itself (other than 1 text box where the date which is set to now() in the properties of that text box). So If I've broken it I have no idea how.

That code should (and did until today) open an existing record. I'm not calling a new record. I'm asking for a record that exists & its opening a new record instead.

Yes the Job ID exists & after clearing the filter I can see that same JobID at the top of the record when I navigate through the records to find it
 
Thought I would simplify by hard coding the JobID to 1

Code:
DoCmd.OpenForm "form0_AddEditJob", , , "JobID=1"

This is what should have opened...

1758787700693.png


This is what opens...

1758787814489.png
 
your Main Form's Data Entry property is Set to Yes.
set it to No.

Property->Data->Data Entry No
 
your Main Form's Data Entry property is Set to Yes.
set it to No.

Property->Data->Data Entry No

Perfect. No Idea why that changed (I don't recall changing it).

When would I want it set to Yes. I edited the form & it saves back with No set.

I assume I can change the Form's Data Entry property back to Yes on the fly should I need to using VB? (A very quick Google search was inconclusive)
 
if you want your Form to be Always on New Record, you set it to Yes.
 
OTHER way to fix this is to add the DataMode option after your filter. This is incase you need to selectively choose add, edit, or read only for different users/situations.

DoCmd.OpenForm "form0_AddEditJob", , , "JobID=" & JobID, acFormEdit
 

Users who are viewing this thread

Back
Top Bottom