UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Problem Going To New Record And Setting Value Of Control, Access 2010    
 
   
jimbofoxman
post Mar 14 2018, 09:12 AM
Post#1



Posts: 358
Joined: 4-April 08



I have a form with 3 fields; WorkOrderID (auto number), ContractNo and JobDate. Their are several subforms as well. Basically what I am trying to do is stop the user from changing the ContractNo for the current record they are editing. If they enter a new ContractNo its going to assume they want a new Work Order and goes to a new record with that number they just entered trying to overwrite the old number. The code I am currently messing with is as follows;

CODE
    Dim intMsg As Integer
    Dim ContNo As Integer
    
    If Me.NewRecord Then Exit Sub
    
    ContNo = Me.ContractNo
    
    'just seeing if it grabs the old number or the newly entered number.  Grabbing the new number
    MsgBox ("New Contract: " & ContNo), vbExclamation
    
    intMsg = MsgBox("Do you want to start a new Work Order?", vbYesNo + vbDefaultButton2 + vbQuestion, "New Work Order?")
    
    Cancel = True
    Me.ContractNo.Undo
    
    If intMsg = vbNo Then
        Exit Sub
    Else
        DoCmd.GoToRecord , , acNewRec
        Me.ContractNo.SetFocus
        Me.ContractNo.Value = ContNo
        Forms![frmWODetails]![sfrmWOTreess].Form.Requery
        'Forms![frmWODetails]![sfrmWOArbs].Form.Requery
        'Forms![frmWODetails]![sfrmWOLifts].Form.Requery
        'Forms![frmWODetails]![sfrmWOVeh].Form.Requery
    End If


If I say yes to a new record, I get runtime error 2108. "You must save the field before you execute the GoToControl action, the GotoControl method or the SetFocus Method. It also still changes the value on the old record to the new Contract Number.

If I select no for the new record it undoes the field change.

Any thoughts? Or a better suggestion?

UPDATE (because I didn't post it originally): Running this on the BeforeUpdate on the ContractNo field.
This post has been edited by jimbofoxman: Mar 14 2018, 09:40 AM
Go to the top of the page
 
theDBguy
post Mar 14 2018, 09:38 AM
Post#2


Access Wiki and Forums Moderator
Posts: 73,276
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Which event are you using for this code?
Go to the top of the page
 
jimbofoxman
post Mar 14 2018, 09:39 AM
Post#3



Posts: 358
Joined: 4-April 08



Sorry........that would help. iconfused.gif

BeforeUpdate
Go to the top of the page
 
theDBguy
post Mar 14 2018, 09:39 AM
Post#4


Access Wiki and Forums Moderator
Posts: 73,276
Joined: 19-June 07
From: SunnySandyEggo


Of the form or the control?
Go to the top of the page
 
jimbofoxman
post Mar 14 2018, 09:40 AM
Post#5



Posts: 358
Joined: 4-April 08



batting 100

On the ContractNo control
Go to the top of the page
 
theDBguy
post Mar 14 2018, 09:42 AM
Post#6


Access Wiki and Forums Moderator
Posts: 73,276
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Thanks. Try adding a Me.Undo line after undoing the control.

Hope it helps...
Go to the top of the page
 
jimbofoxman
post Mar 14 2018, 09:46 AM
Post#7



Posts: 358
Joined: 4-April 08



So I did Me.Undo after Me.ContractNo.Undo. That did make it not change the previous information in that control, I still get Run Time Error 2108 on Me.ContractNo.SetFocus
Go to the top of the page
 
theDBguy
post Mar 14 2018, 09:51 AM
Post#8


Access Wiki and Forums Moderator
Posts: 73,276
Joined: 19-June 07
From: SunnySandyEggo


Hmm, there may be no way around it since you're using the BeforeUpdate event. You may have to just remove or comment out the SetFocus line and just make the ContractNo the first one in the Tab Order.

Otherwise, I am wondering if this whole thing can be avoided and just "lock" the control for existing records and just give the user a button to create a new work order.

Just a thought...
Go to the top of the page
 
jimbofoxman
post Mar 14 2018, 09:59 AM
Post#9



Posts: 358
Joined: 4-April 08



Ok thanks for the input. I'll look into a different avenue.
Go to the top of the page
 
theDBguy
post Mar 14 2018, 10:11 AM
Post#10


Access Wiki and Forums Moderator
Posts: 73,276
Joined: 19-June 07
From: SunnySandyEggo


Good luck!
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    26th September 2018 - 02:40 AM