473,379 Members | 1,235 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Save and Clear

MitchR
65 64KB
I Have created a table for data entry. The table and accompanying form used to enter data is used for returning leased assets back to a lease holder. My question is this: I want to script a Save and Clear Button on my data entry form to write the data back to the table so that I can run reports against the table & clear the form for the next item to be entered. I do not want the data to be visible to the user once the button is pressed. Here is what I have but I receive errors upon launch:

Private Sub SaveMonitor_Click()
On Error GoTo Err_SaveMonitor_Click
'Set the save statement to disable command button once Save button is clicked.

DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunSQL "UPDATE MonitorReturn SET completed = " & -1 & " WHERE DateShip = '" & [Forms]![MonitorReturn]![MonitorSerial#] & "' ;"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.SetWarnings True
'Requery checkbox to show checked
'after update statement has ran
'and disable send mail command button
Form_MonitorReturn.SetFocus
Form_MonitorReturn_SaveMonitor.Enabled = False
Recordset.CreateNew

Exit_SaveMonitor_Click:
Exit Sub


I am pulling my hair out!!!
Nov 10 '06 #1
6 5048
NeoPa
32,556 Expert Mod 16PB
You really need to provide more information about the error.
Please read this post ( http://www.thescripts.com/forum/thread559246.html ) as it will tell you how best to get your questions answered.
Specifically here, post the code as code and provide some info about what error you're getting.
Nov 11 '06 #2
MMcCarthy
14,534 Expert Mod 8TB
In the form properties set the Data Entry property under the Data tab to Yes.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub SaveMonitor_Click()
  3. On Error GoTo Err_SaveMonitor_Click
  4. 'Set the save statement to disable command button once Save button is clicked.
  5.  
  6. DoCmd.SetWarnings False
  7.  
  8. ' change DoCmd.RunCommand acCmdSaveRecord to
  9. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  10.  
  11.  
  12. DoCmd.RunSQL "UPDATE MonitorReturn SET completed = " & -1 & " WHERE DateShip = '" & [Forms]![MonitorReturn]![MonitorSerial#] & "';"
  13.  
  14. ' remove this DoCmd.RunCommand acCmdSaveRecord line
  15.  
  16. DoCmd.SetWarnings True
  17.  
  18. 'Requery checkbox to show checked
  19. Me.completed.Requery
  20.  
  21. Form_MonitorReturn.SetFocus
  22. Form_MonitorReturn_SaveMonitor.Enabled = False
  23.  
  24. ' go to new record
  25. DoCmd.GoToRecord acDataForm, "MonitorReturn", acNewRec
  26.  
  27. Exit_SaveMonitor_Click:
  28. Exit Sub
  29.  
  30. Err_SaveMonitor_Click:
  31.  
  32. End Sub
  33.  
  34.  
Nov 12 '06 #3
MitchR
65 64KB
I still have one problem... I want to Grey Out the Save and Clear command button. I have followed the exmples from other threads and simplified my code and the save and clear function works great! Thank you for those. My issue is this : When I click my save button I would like to " Grey out the save button. Unfortunately when I execute the save command I get a Runtime error '2164' You Can't Disable a control while it has the focus and prompts me to debug. I have attempted to every which way to fix the issue with no success. The Debug point is Me.SaveMonitor.Enabled = False I am must appreciative for any assistance. Otherwise I can just comment out the grey out piece and go along as is... Here is my code :

Expand|Select|Wrap|Line Numbers
  1.  Private Sub SaveMonitor_Click()
  2. Dim mydate As Variant
  3. mydate = Date
  4. MsgBox "Please Remember that Monitors are to be shipped directly to Site." & vbCrLf & _
  5.        "Monitor" & vbCrLf & _
  6.        "Address1" & vbCrLf & _
  7.        "Address2" & vbCrLf & _
  8.        "Address3", , "Dell Monitor Alert"
  9.     DoCmd.SetWarnings False
  10.     'Requery checkbox to show checked after statement has ran and disable command button
  11.     Me!Completed = -1
  12.     Me.Completed.Requery
  13.     DoCmd.SetWarnings True
  14.     Me.SaveMonitor.SetFocus
  15.     'Diasble the Save & Continue button
  16.     Me.SaveMonitor.Enabled = False
  17.     DoCmd.GoToRecord acDataForm, "MonitorReturn", acNewRec
  18.  
  19. Exit_SaveMonitor_Click:
  20.     Exit Sub
  21. End Sub 
Dec 4 '06 #4
MitchR
65 64KB
Ok I moved the focus to a "Return to Switchboard" Control button and that resolved the issue, But ... One problem though .... it greys out permanently. I was thinking that an IF statement might be key but I cannot get the IF statement to see Completed = -1 in the completed column of the table. My Completed column in my table is a yes/no with lookup as textBox. 0 = not completed & -1 = completed Here is my updated code:
Code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub SaveMonitor_Click()
  2. Dim mydate As Variant
  3. Dim Completed As Varian
  4. tmydate = Date
  5. MsgBox "Please Remember that Dell Monitors are to be shipped directly to Dell." & vbCrLf & _       
  6. "Address1" & vbCrLf & _       
  7. "Address2" & vbCrLf & _       
  8. "Address3" & vbCrLf & _       
  9. "Address4", , 
  10. "Dell Monitor Alert"    
  11. DoCmd.SetWarnings False    
  12. 'Requery checkbox to show checked after statement has ran and disable command button    
  13. Me!Completed = -1    
  14. Me.Completed.Requery    
  15. DoCmd.SetWarnings True    
  16. Me.Exit.SetFocus    
  17. 'Diasble the Save & Continue button   
  18.  If Me!Completed = -1 Then
  19. Me.SaveMonitor.Enabled = False
  20. Else    
  21. If Me!Completed = 0 Then        
  22. Me.SaveMonitor.Enabled = True    
  23. End If    
  24. DoCmd.GoToRecord acDataForm, "MonitorReturn", acNewRecExit_SaveMonitor_Click:    Exit SubEnd Sub
  25.  
Dec 5 '06 #5
NeoPa
32,556 Expert Mod 16PB
I can't see that the code to ungrey would ever be executed.
You need to trigger the ungreying from somewhere that will get run even when the command is greyed out.
Your solution to the earlier problem is good - well done.
The coding to set the status could be more clearly written as :
Expand|Select|Wrap|Line Numbers
  1. ...
  2. Me.Exit.SetFocus
  3. 'Disable the Save & Continue button   
  4. Me.SaveMonitor.Enabled = Not Me.Completed
  5. ...
I'm assuming here that there is a point to enabling it in this code.
I don't presume to know everything that goes on in your code, although it seems illogical from here.
Dec 5 '06 #6
MitchR
65 64KB
Ok ... Thank you to All who have helped me with this project. I got a Final Solution to my issue of Greying out the Button. On Form properties ON Current, The event procedure should be scripted :
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Form_Current()
  2.  
  3.     Dim Completed As Variant
  4.  
  5.     If Me.Completed = True Then
  6.         Me.SaveMonitor.Enabled = False
  7.  
  8.     Else
  9.         Me.SaveMonitor.Enabled = True
  10.     End If
  11. End Sub 

Thank you NeoPa and MMCCarthy For all your Support !!! I could not have doe this with out you.
Dec 6 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: William Schubert | last post by:
Is there a common defintion of Clear that applies to both objects and collections? If so, where is it documented. My preconceived notion is that Clear means "reset the object to its initial...
0
by: Doslil | last post by:
I have a form which is designed to only data entery.When i try to open to form in the run form I have the following errors 1. when i open the form I get an error message saying "Access can't...
5
by: tshad | last post by:
When I log of I do: HttpContext.Current.Session.Clear() FormsAuthentication.SignOut() The problem is that it clears the variables that I set up in my Session_Start function in my...
2
by: Rubber Steve | last post by:
Can someone please tell me what is wrong with my code. The add button works fine and when I save the added record is saved but for some reason when I edit and save the information that I edited...
3
by: DHarry | last post by:
How can I clear a text file without deleting and creating a new (empty) file?
5
by: hp_1981 | last post by:
Hi Is there anyway avoiding users to save my web pages? this idea came to my mind when I tried to save a web page, but in the middle of saving progress something like the following error...
3
by: Prabhupl | last post by:
Hi I have an problem in asp.net code behine vb.net. :confused: I need to clear the controls while postback the page. eg:- i am getting the input of an child information(name, age, qualification,...
0
by: crazyyellowguy | last post by:
hi, This is my first post in this forum and I just wanted to thank you for even taking a look at my post. The class that I am writing the C code for is my first computer class and my knowledge is...
5
by: karsagarwal | last post by:
I have a bounded form and after I click the button to update/save. THe fields are still there. Is there a way to clear off the fields in the bounded form. Thanks, SA Here's the code that I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.