Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button to save information for Data Entry 1

Status
Not open for further replies.

Eleventy

Technical User
Aug 12, 2010
17
US
So I am currently using a subform that opens w/ "Data Entry = True" for a data entry form. However, what I would like is a button that updates the text boxes to a table but I am having a huge brain fart and can't think of a way to do this.

It would be something like
txtCorporation
txtAddress
txtCity
txtCounty
txtState
txtPhone_Number

to tblCorporation
Corporation
Address
City
County
State
Phone_Number

Any ideas?
 
Any reason you are using an unbound form?
 
behind your button you could use the following on the click event.

dim db as dao.database
dim strsql as string

set db =currentdb

strsql ="insert into tblcorporation (Corporation,Address,City,County,State,Phone_Number)
values ('" & txtcorporaion & "','" & txtaddress & "','" & txtcity & "','" & txtcounty & "','" & txtstate & "','" & txtphone_number & "')"

db.execute strsql

db.close
set db=nothing

Hope this helps

 
If you are opening a form with DataEntry = True then presumably you must be working with a bound form because it is moot if you are using an unbound form.

So to save a record for a bound form specifically, you can use

Code:
If Me.Dirty Then Me.Dirty = False
OR you can use
Code:
DoCmd.RunCommand acCmdSaveRecord

But the first one is best because it only attempts a save if there is anything to save.

If you are using an unbound form I would ask why? Because there are times that may require an unbound form but most of the time that is not the case and if you use one then you are eliminating Access from doing all of the work that you would otherwise have to code for.

Bob Larson
Free Access Tutorials and Samples:
 
I do not currently have an unbound form but I did not know if having an unbound form would be necessary to save this. My main issue is that I have much less savvy people who will likely be doing a lot of the entry and I wish to avoid having somebody type in some random stuff and then have access add in useless information.

What exactly does "Me.Dirty Then Me.Dirty = False" mean?
 
If Me.Dirty Then Me.Dirty = False

means if the form has been dirtied (a change has occurred to at least one control bound to data, or a new record has been started) then it sets it to FALSE which means that it forces a save of data to the table to which the form is bound.

Moving to a new record or navigating to another existing record will also cause a save to be issued.

If you want to validate that all data has been entered to your satisfaction before saving you use the FORM'S BEFORE UPDATE event so if the code you put in there finds that all required fields aren't filled out (for example) then you can issue a

Cancel = True

which will stop the update from happening.

I hope that helps.

Bob Larson
Free Access Tutorials and Samples:
 
So, I understand that by using the Dirty criteria it automatically tries to save assuming the form has been changed. What I am looking for is a way to ensure that all the text boxes/combo boxes have been filled before saving and a prompt to continue if certain non vital things have not been filled. Sorry if I am being vague or asking for too much help but I am having trouble figuring out how to do this.

IE Not having a customer's phone number is a big deal but not knowing their county is not a huge issue.
 
Did you even bother to read my last post completely? You are asking for the EXACT INFORMATION I just gave you. You use the form's BEFORE UPDATE event to validate. Go re-read the post again and see if you can catch on to it.

Bob Larson
Free Access Tutorials and Samples:
 
So I am bumping this in hopes of getting more help.

I understand the concept of using the dirty command to verify if a record has been changed but I am having an issue figuring out how to link several text boxes together so that all of them must be verified as being dirty to unlock a button which runs a command that saves the data and then clears it so that another set of information can be entered.

Help would be much appreciated.
 
Sample:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim blnNotFilledOut As Boolean
Dim strMsg As String

If Len(Me.MyTextBox & "") = 0 Then
   blnNotFilledOut = True
   strMsg = "This Field Name" & vbCrLf
End If

If Len(Me.MyOtherTextBox & "") = 0 Then
   blnNotFilledOut = True
   strMsg = strMsg & "This Other Field Name" & vbCrLf
End If

If Len(Me.MyComboBox & "") = 0 Then
   blnNotFilledOut = True
   strMsg = strMsg & "This Combo Box Name" & vbCrLf
End If


If blnNotFilledOut Then
   strMsg = "These need to be filled out before continuing: " & vbCrLf & strMsg
   MsgBox strMsg, vbExclamation, "Validation Error"
   Cancel = True
End If

So, if any of my listed controls are empty or null, it will flip a flag and fill in part of a message. So, then at the end of the code it checks to see if the flag (boolean) has been flipped and if so it puts together the rest of the message and then also initiates Cancel = True so it won't continue until the missing controls are filled in. And it gives them a message telling them which controls are missing data (we do it this way so they don't keep getting error messages and can get one to go back and fill them in. If they don't fill in all of them it will do it to them again but it won't give them 3 or 4 messages if you were to do the message right away and they weren't filling in all of the fields. Saves them from getting a message, going to fill that one out, saving and then it does it for the next missing and so on. This way it catches them all at once and is much more user-friendly.


Bob Larson
Free Access Tutorials and Samples:
 
How are ya Eleventy . . .

Just another approach which easily allows you to scan a large number of controls and makes it easy to add/remove controls for validation.

In the [blue]Tag[/blue] property of each control you wish to validate, add a question mark [blue]?[/blue] (no quotations please). Then in the forms [blue]Before Update[/blue] event, try the following:
Code:
[blue]   Dim ctl As Control, DL As String
   
   DL = vbNewLine & vbNewLine
   
   For Each ctl In Me.Controls
      If ctl.tag = "?" Then
         If Trim(ctl & "") = "" Then
            MsgBox "'" & ctl.Name & "' Requires Data!" & DL & _
                   "Can't save without '" & ctl.Name & "'!", _
                   vbCritical + vbOKOnly, _
                   "Missing Data Detected! ..."
            Cancel = True
            ctl.Name.SetFocus
            Exit Sub
         End If
      End If
   Next[/blue]
[blue]Your Thoughts? ...[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Using AceMan's approach you can also use the tag property to store a more custom messsage. You can put something like this in the Tag.

?Provide a valid report date identifiying when the report is due to corporate.

Then just modify AceMan's to check that the first character is a "?"
If Left(ctl.Tag, 1) = "?" Then ...
And then in your prompt you can put in addition something like this:
.. & Mid(ctl.Tag, 2)..
to print the cusom message
 
Thank you TheAceMan1, I will probably toy around with that later.

I currently have put in boblarson's code in my BeforeUpdate column and it works fine, however I have a few more questions.

I guess my main problem here is that I am going to have people with very low computer literacy using this database on occasion and I am attempting to make it as user friendly as humanly possible.

I tried to put in a Clear Parameters button/a Close button that sets all the text boxes to Null if you put something in but didn't have all the information and needed to navigate away. However, this still activates the boolean not filled out Validation Error.

Any suggestions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top