Cmd Click --- check the values first,append record and then delete them.

Hi all,
I want to execute below code but it seems absolutely fail,
please help:

Private Sub AddSpec_cmd_Click()
On Error GoTo Err_AddSpec_cmd_Click

        If IsNull(Me.Model) Then
    MsgBox " Enter Model Name", vbOKOnly, "Model name empty"
        End If
        Model.SetFocus

        If Inputvoltage.Value < 11 Then
    MsgBox " Input correct voltage rate ", vbOKOnly, "Input voltage"
        End If

        Dim db As Database
        Set db = CurrentDb

        db.Execute "Appendix model spec1_qry", dbFailOnError
        db.Execute "DELETE * FROM [Appendix model specification_tbl]",
dbFailOnError

Exit_AddSpec_cmd_Click:
Exit Sub

Err_AddSpec_cmd_Click:
    MsgBox Err.Description

Resume Exit_AddSpec_cmd_Click:
End Sub

I want all condition must meet the criteria first
and then the execution is progressed.It seems
there will be many If..Then statement and I'm confuse
how to write a good code.

In fact,I want to add one more condition.
There are more 3 fields,if all of their values are 0,
the appending execution is fail




0
New_Access
12/5/2007 12:18:53 PM
access.formscoding 7493 articles. 0 followers. Follow

3 Replies
647 Views

Similar Articles

[PageSpeed] 53

What's wrong with it? Let me count the ways:

- You put your "Model.Setfocus" command outside the error block.
- You need to use (IMO) "Me.Model.Setfocus"
- You need to add the command EXIT SUB inside the error blobk
- DIM statements shoudl ALWAYS occur first in a Sub or Func (good coding 
practice)

You've never really written code before in ANY language, have you? (Just 
asking)


0
Utf
12/5/2007 4:33:17 PM
What I typically do is something like:

Private Sub AddSpec_cmd_Click()
On Error GoTo Err_AddSpec_cmd_Click

Dim db As Database
Dim strMessage As String

  If IsNull(Me.Model) Then
    strMessage = strMessage & _
      " Enter Model Name" & vbCrLf
  End If

  If Inputvoltage.Value < 11 Then
    strMessage = strMessage & _
      " Input correct voltage rate " & vbCrLf
  End If

  If Len(strMessage) = 0 Then
    Set db = CurrentDb
    db.Execute "Appendix model spec1_qry", dbFailOnError
    db.Execute "DELETE * FROM [Appendix model specification_tbl]", _
      dbFailOnError
  Else
    MsgBox strMessage, vbOkOnly, "Errors Occurred"
  End If

Exit_AddSpec_cmd_Click:
  Exit Sub

Err_AddSpec_cmd_Click:
  MsgBox Err.Description
  Resume Exit_AddSpec_cmd_Click:

End Sub

Since focus can only be on a single control, it's (obviously) not possible 
to set focus to all of the erroneous fields. You could keep choose to set 
focus to, say, the first control that had an error.

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"New_Access" <New_Access@project.com> wrote in message 
news:%23qzS0ezNIHA.1208@TK2MSFTNGP03.phx.gbl...
> Hi all,
> I want to execute below code but it seems absolutely fail,
> please help:
>
> Private Sub AddSpec_cmd_Click()
> On Error GoTo Err_AddSpec_cmd_Click
>
>        If IsNull(Me.Model) Then
>    MsgBox " Enter Model Name", vbOKOnly, "Model name empty"
>        End If
>        Model.SetFocus
>
>        If Inputvoltage.Value < 11 Then
>    MsgBox " Input correct voltage rate ", vbOKOnly, "Input voltage"
>        End If
>
>        Dim db As Database
>        Set db = CurrentDb
>
>        db.Execute "Appendix model spec1_qry", dbFailOnError
>        db.Execute "DELETE * FROM [Appendix model specification_tbl]",
> dbFailOnError
>
> Exit_AddSpec_cmd_Click:
> Exit Sub
>
> Err_AddSpec_cmd_Click:
>    MsgBox Err.Description
>
> Resume Exit_AddSpec_cmd_Click:
> End Sub
>
> I want all condition must meet the criteria first
> and then the execution is progressed.It seems
> there will be many If..Then statement and I'm confuse
> how to write a good code.
>
> In fact,I want to add one more condition.
> There are more 3 fields,if all of their values are 0,
> the appending execution is fail
>
>
>
> 


0
Douglas
12/5/2007 4:57:46 PM
Thank's All,
Coding is a new thing for me so I always get stuck if I
have to use some code.
Can you advise some good resource for learn coding.



"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:#Jeu2$1NIHA.2208@TK2MSFTNGP06.phx.gbl...
> What I typically do is something like:
>
> Private Sub AddSpec_cmd_Click()
> On Error GoTo Err_AddSpec_cmd_Click
>
> Dim db As Database
> Dim strMessage As String
>
>   If IsNull(Me.Model) Then
>     strMessage = strMessage & _
>       " Enter Model Name" & vbCrLf
>   End If
>
>   If Inputvoltage.Value < 11 Then
>     strMessage = strMessage & _
>       " Input correct voltage rate " & vbCrLf
>   End If
>
>   If Len(strMessage) = 0 Then
>     Set db = CurrentDb
>     db.Execute "Appendix model spec1_qry", dbFailOnError
>     db.Execute "DELETE * FROM [Appendix model specification_tbl]", _
>       dbFailOnError
>   Else
>     MsgBox strMessage, vbOkOnly, "Errors Occurred"
>   End If
>
> Exit_AddSpec_cmd_Click:
>   Exit Sub
>
> Err_AddSpec_cmd_Click:
>   MsgBox Err.Description
>   Resume Exit_AddSpec_cmd_Click:
>
> End Sub
>
> Since focus can only be on a single control, it's (obviously) not possible
> to set focus to all of the erroneous fields. You could keep choose to set
> focus to, say, the first control that had an error.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "New_Access" <New_Access@project.com> wrote in message
> news:%23qzS0ezNIHA.1208@TK2MSFTNGP03.phx.gbl...
> > Hi all,
> > I want to execute below code but it seems absolutely fail,
> > please help:
> >
> > Private Sub AddSpec_cmd_Click()
> > On Error GoTo Err_AddSpec_cmd_Click
> >
> >        If IsNull(Me.Model) Then
> >    MsgBox " Enter Model Name", vbOKOnly, "Model name empty"
> >        End If
> >        Model.SetFocus
> >
> >        If Inputvoltage.Value < 11 Then
> >    MsgBox " Input correct voltage rate ", vbOKOnly, "Input voltage"
> >        End If
> >
> >        Dim db As Database
> >        Set db = CurrentDb
> >
> >        db.Execute "Appendix model spec1_qry", dbFailOnError
> >        db.Execute "DELETE * FROM [Appendix model specification_tbl]",
> > dbFailOnError
> >
> > Exit_AddSpec_cmd_Click:
> > Exit Sub
> >
> > Err_AddSpec_cmd_Click:
> >    MsgBox Err.Description
> >
> > Resume Exit_AddSpec_cmd_Click:
> > End Sub
> >
> > I want all condition must meet the criteria first
> > and then the execution is progressed.It seems
> > there will be many If..Then statement and I'm confuse
> > how to write a good code.
> >
> > In fact,I want to add one more condition.
> > There are more 3 fields,if all of their values are 0,
> > the appending execution is fail
> >
> >
> >
> >
>
>


0
New_Access
12/6/2007 1:13:31 AM
Reply:

Similar Artilces:

Button to go to a specific record in a form
Hello, I have two forms. I need to use a command button to go to a second form's specific record. a. In the wizard, when it is time to chose the fields to match, there is nothing in the left side of the screen. b. How do I do this in code. Thnaks for all of your help. Joe In the Click event of the command button, use the primary key field of the record you want to open in the second form in the OpenForm Where argument. This is a good example in VBA Help. -- Dave Hargis, Microsoft Access MVP "Joe C" wrote: > Hello, > > I have two forms. I need to use a c...

Emptying 'Deleted Items' folder on exit
I am running WLM version 2009 (Build 14.0.8089.0726) on Windows 7 with all the latest updates. I have 'Empty messages from the Deleted Items folder on exit' checked under Maintenance, but they're all still there when I exit and restart WLM. Is there another setting I should be looking at to make this work? TIA, -- SC Tom Tom, I experienced the same thing earlier today. I'm new to WLM and found that if you "checked" the ''Empty messages from the Deleted Items folder on > exit' after there were items in the Deleted Items folder, it ...

Max of value from DataGroup2 within DataGroup1
Hello - I have a table with data as follows below. I am trying to build a query that will give me the record with MAX of specDiffMax [value] for each TestFreq [DataGroup 2] within each TestNum [DataGroup1]. ID TestNum TestFreq specDiffMax -------------------------------------------- 4889683 Test 1 1710 3.669998 5123289 Test 1 1710 2.882999 4817314 Test 1 1710 3.102001 5134007 Test 1 1710.2 3.573002 4896056 Test 1 1710.2 3.355 4914480 Test 1 1710.2 3.515999 4889685 Test 2 1710.4 3.333 4896057 Test 2 1710.4 3.450001 4914481 Test 2 ...

How to check the style of window is not WS_EX_APPWINDOW ?
Hello There How can I check whether the extended style of window is not WM_EX_APPWINDOW.( Means it won't have entry in taskbar when it visible. I can check whether the it has WS_EX_APPWINDOW style like this if (::GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_APPWINDOW) TRACE("App Window\n"); But how can I do the reverse thing ? Example: 0010101 Real 0110101 Mask The Bitwise AND gives a 1 if the real and the mask are 1, such as 00101100 00100100 AND ---------- 00100100 In this situation, we know that at least some of the mask is true, -- now -- Take the binary number...

How to Change Value of Active Control
I'm writing a routine to change the value of any Active Control to null. I can get the name of the control using ActiveControl.Name but I can't figure out the syntax to change the value of this control. I've tried assigning it to variables but variables aren't working in a: Forms![variable]![variable] = "" Help "Sondreli" <Sondreli@discussions.microsoft.com> wrote in message news:AA05A840-2AFE-4F98-ABE9-5D2DD17AE0B8@microsoft.com... > I'm writing a routine to change the value of any Active Control to null. > I > can g...

How do I get deleted items that stay in inbox with line thru them.
I inherited a computer at work. Outlook is setup so that when I delete a message it stays in the inbox, with a line thru it. How do I get the deleted items to go automatically to the deleted item folder? "rwwhit" <rwwhit@discussions.microsoft.com> wrote in message news:7D17761E-CD1B-4D04-BACB-B0D837C4DD93@microsoft.com... >I inherited a computer at work. Outlook is setup so that when I delete a > message it stays in the inbox, with a line thru it. How do I get the deleted > items to go automatically to the deleted item folder? That's normal behavior...

Excel 'hangs' when deleting a row
when i delete a row in excel 2000, everything locks up! and when lookup at Task Manager/Processes, it's MEM USAGE goes up to 22K o more! i tried doing it in another file but i experienced no error. the dat is in LAN. all data are filtered when the deletion began. however i ca delete files before. please help, anyone.... -- Message posted from http://www.ExcelForum.com The best thing is to free up memory (assuming your file is large). Clos all applications you do not require at the time and any workbooks no in use. Dunca -- Message posted from http://www.ExcelForum.com ...

Using a VBscript to copy/delete/move Outlook messages
I need to write a VBscript to: - open my Outlook (2000 or XP) mailbox - read the list of the folders in either the Exchange Mailbox and in local ..pst files - open each folder and subfolders - read information about messages (i.e. sender, recipient, creation date, and so on) - move, copy or delete messages based on the above information Can anybody please provide a pointer to a sample I can start from? Regards Marius ...

IE8 was deleted from my windows 7 and I cannot find correct downlo
I have a two month old Toshiba and deleted IE8 because of crashes. Trying to find the correct download to reinstall. The IE8 homepage just says it is included in windows 7 but does not show the download file....... ARRRG. Tried Vista IE8 download file but message says it not the correct operating system. On Sun, 21 Mar 2010 20:50:01 -0700, pawntonian <pawntonian@discussions.microsoft.com> wrote: >I have a two month old Toshiba and deleted IE8 because of crashes. Trying to >find the correct download to reinstall. The IE8 homepage just says it is >included in wind...

Validation Rule for field values
I have a database that includes a phone number field. I want to prevent a user from creating a new record that contains a phone number that is currently in a record that exists in the database.I am using a form for data entry into the table. Somehow I'd like for there to be a check to see if the phone number typed into the phone number field to be checked against existing phone numbers in the database.I've researched various sources but haven't been able to find the solution. I'm not familiar with VB so any replies that suggest using that will probably not work for me. Sorry, j...

How to delete duplicate data
Hi, I am using excel to consolidate monthly room booking data. I have a date column and time column. May I know how to to delete those rows which contains duplicate data with same date stated in the date columnand and same time range in the time column? Thank you. Data>filter>advanced filter, unique records only and copy to another location -- Regards, Peo Sjoblom Excel 95 - Excel 2007 Northwest Excel Solutions www.nwexcelsolutions.com (Remove ^^ from email) "PL" <PL@discussions.microsoft.com> wrote in message news:F45DAE2B-252D-4E17-81D8-0F4C060BCB21@m...

Can you delete and empty an open email
Hi there Can you delete and empty an open email? I know I can delete and empty a closed email by holding down shift and then deleting, but have not been able to figure out how to delete and empty from an open email. Is this even possible? Thanks for your help. Kylie On Wed, 18 May 2005 20:01:03 -1000, Kylie B"" <KylieB@discussions.microsoft.com> wrote: > Hi there > > Can you delete and empty an open email? I know I can delete and empty a > closed email by holding down shift and then deleting, but have not been > able > to figure out how to delet...

How do I convert time (hh:mm) to value ($$) in Excel?
Would like to calculate cost of time. Eg. Cost for production down time per minute is $100. Says production doen for 3.5 hrs, what is formula shall I apply in order to generate the cost (in $$). =3.5*60*100 "ahfen79" wrote: > Would like to calculate cost of time. Eg. Cost for production down time per > minute is $100. Says production doen for 3.5 hrs, what is formula shall I > apply in order to generate the cost (in $$). =(3.5/24)*60*100 -- Regards Dave Hawley www.ozgrid.com "ahfen79" <ahfen79@discussions.microsoft.com> wrote in ...

Automatically generate a new record
Can I autumatically generate a new record adding information (future date) from a current record? Yes. In your form have Double-click event call an append query that pull data from your form fields to append one record. INSERT INTO [YourTableToAppendInto] ( Field1, Field2, Field3, Field4 ) SELECT TOP 1 [Forms]![YourForm]![1stField] AS [X], [Forms]![YourForm]![2ndtField] AS [Y], [Forms]![YourForm]![2rdtField] AS [Z], [Forms]![YourForm]![4thtField] AS [A]; -- KARL DEWEY Build a little - Test a little "Crown Jenny" wrote: > Can I autumatically generate a new record addin...

deny ability to delete sent items
Environment is Win2k3 Server and Exch2k3. We would like to impliment a Group Policy that would remove users ability to delete the items in their Sent Items folder. It would be OK if items could be removed after Archiving if necessary. It appears that deleted Sent Items do not go to Deleted Items folder, so dumpster retention policy doesn't seem to be a solution. Any ideas? I am 99.9% certain that this is not possible through group policy. I'm very certain that while it might be possible, it would be extremely difficult to implement and manage. -- Ed Crowley MVP - Exchange &quo...

using program to record audio comment and compress audio to MP3
I can use VBA to record an audio comment into a Word file using Selection.InlineShapes.AddOLEObject ClassType:="SoundRec", FileName:="", _ LinkToFile:=False, DisplayAsIcon:=True, IconFileName:= _ "C:\WINDOWS\system32\sndrec32.exe", IconIndex:=0, IconLabel:="Wave Sound" BUT but by default the file is stored as a PCM at 44kHz and 16 bit stereo whcih is about 200kB per second Sound recorder (which is used to do the recording) allows me to manually convert this to a MP3 and a much smaller file e.g. 3kB per second Is there any way I can aut...

recording keystrokes
How do I record keystrokes and then evoke a command to repeat those keystrokes? For instances; I want to change the first word in a numbered list in the document all the way through the document. You cannot record loops with the macro recorder. The following will replace the first word in each paragraph in the selected text with the word(s) defines in sText Sub ReplaceFirstWord() Dim oPara As Paragraph Dim sText As String sText = "Replacement Text" For Each oPara In Selection.Range.Paragraphs oPara.Range.Words(1).Text = sText & Chr(32) Next oPara End ...

Import Customer Records
I am trying to import customer records and I am running into the following error: DOC 1 ERROR: Are you sure you want to delete this customer record? Ln 810 Col 2, Update module, Last CBOM field read was root.'Customer ID', Last window field visited was 'Clear Button' of window 'RM_Customer_Maintenance' of form 'RM_Customer_Maintenance' Any ideas? Thanks! Are you on the latest integration manager service pack? Best regards, -- MG.- Mariano Gomez, MIS, MCP, PMP Maximum Global Business, LLC http://www.maximumglobalbusiness.com The Dynamics GP Blogster at h...

Getting an UnBound control value into a Table field??????
I have a form that calculates a production rate in "parts per hour". This form needs to be able to differentiate between Line work, Cutter work, Side work, and Blister work. I created a drop down list for selecting the "Study Type" as listed above. I then created a text box for each "study type". When I select the "study type" each text box checks to see if the selection applies to it and makes the calculation if it does apply. The code for the "Line" study is as follows: =IIf([StudyType]="Line",2700?/[SecondsPerPart])...

How do I read in a record / row from a table.
Hi, I have a form where I need to read in the parameter setting for the current user. I know I can use DLookup but I have to lookup about 14 different parameters off a single row. But that seems quite inefficient. I need to read the record and extract the values from the record / row. Thanks. -- Dennis Dennis Here's one possible approach ... there are many ... You could create a form that is bound to that record, and make the form hidden. You can refer to controls on the form with: Forms!YourForm!YourControl Regards Jeff Boyce Microsoft ...

Excluding multiple checking accounts from budget totals?
Howdy! Running Money06, and I have two checking accounts synching through Bank of America. Everything there is working well, but one thing that I dont like is that the totals for BOTH accounts are added together. I have two accounts, 'personal' and 'class', and both accounts are shown in the net balance statements, the 'spending by catagory' chart on the home page etc. I would like to keep synched with my class account, but want it excluded from all of the balances.. any suggestions? "Raichean" <Raichean@discussions.microsoft.com> wrote in mes...

Return a "" value from a formular
Any help greatly appreciated: I have 2 formulars that works, but I want them to return nothing eg "" when there is nothing entered into a cell, at the moment they return the 'false' value. My formulars are: =IF(O12>O11,"End milestone deadline passed","OK") =IF(AND(O12>O11,OR(D12>D11,E12>E11,F12>F11,G12>G11,H12>H11,I12>I11,J12>J11,K12>K11,L12>L11,M12>M11,N12>N11)),"End milestone passed and 'Actual's' late","End milestone passed but 'Actual's' OK") =IF(isblank(O12),&...

Sum of Top Values in Access Report
In an Access report, I'm presenting the top 15 cost values in the detail section. I have a counter to do start a new print page. That is working, but I also want to present the group total (=sum[netofreturns]) with the total of the top 15 values [top15only] and calculate the percentage of the top 15 to the group total (top 15/group total) in the group footer. ...

Problems Sending Messages to domains w/ multiple MX records
Got a question for the Exchange experts out there. We have a wierd situation occuring where e-mails we send to domains w/ multiple MX records either do not get through or the recipient receives the message multiple times until we manually delete the message in the ESM/Queues. All other messages get through fine. We have come to this conclusion (problem is with multiple MX records) by testing the domains we are having problems w/ using www.dnsstuff.com DNS Lookup tool for MX records. All of them come back w/ multiple MX records. Here is what has changed recently: We moved to a new locat...

InterOrg succesful but no deletions ??
Hello, I use InterOrg between two different exchange organizations and InterOrg is working fine. I get the "succesful" message so InterOrg is copying all the contacts from a public folder to another. In my InterOrg configuration i marked also "deletions" so when i delete a contact in the publisher, then it should also be deleted in the subscriber, right ? But this is not the case...anyone any idea why this is ? GrtZ, Philippe ...