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
> Command Button Gets "next Id" But I Do Not Want It To Run If Id Is Not Blank, Access 2010    
 
   
jmkeuning
post Dec 4 2017, 05:21 PM
Post#1



Posts: 65
Joined: 20-October 15



I have a pretty simple MediaID field that is formatted as 00001. I have a pretty simple function that queries the highest existing mediaID and calculates the next mediaID. If a user hits a button, the next mediaID is entered in the MediaID field.

CODE
Private Sub Command77_Click()
Forms![frmMediaEntryCopy]![frmNextMediaIDSub].Form.Requery
MediaID = Forms!frmMediaEntryCopy!frmNextMediaIDSub.Form.NextMediaID
MediaNum = Forms!frmMediaEntryCopy!frmNextMediaIDSub.Form.NextNum
End Sub


The problem is that the button will overwrite an existing MediaID if the user is not on a new record. I would be really happy if I could pop-up a message with a warning if the field is not empty. Now, there are some legit reasons that someone would want to overwrite, so I can imagine a form with a y/n question followed by appropriate workflow, but I would like to set that aside and just understand how to check the MediaID field, and if the MediaID field is blank run the update with the next number, and if the MediaID is not blank, throw an error "MediaID must be blank to assign the next number" and cancel the operation.

Thanks!
Go to the top of the page
 
theDBguy
post Dec 4 2017, 05:50 PM
Post#2


Access Wiki and Forums Moderator
Posts: 71,225
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Maybe you could start with something like:

If IsNull(Me.MediaID) Then
'do stuff
Else
'ask first
End If

Hope it helps...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    14th December 2017 - 10:18 AM