Private Sub Cmd_AddAnother_Click()
Dim strMsg As String
strMsg = "Do you want to add another License?"
If MsgBox(strMsg, vbYesNo Or vbQuestion) = vbYes Then
DoCmd.GoToRecord , "Frm_NewPE", acNewRec
End If
End Sub
When I click the button, the message comes up but when I click yes, nothing happens??? It's not giving me an error message and it's not clearing my form to enter new records. It just does nothing...
What am I doing wrong?
The message comes up but it does not go to a new record for me to add another record
The Command button is within the form and after I've added the 1st record I want to add another one and this is what it is not doing
I know the message box appears but I doubt it shows a question mark as the syntax was wrong. As a result it won't run the next line to go to a new record unless you change the message box as I explained last time.
I.e. use + and not Or
So I have this form where I enter new license information. Once I have entered everything in the designated fields I click add and it inserts all my data into a table. What I am trying to do is be able to go to a new record and enter the same information for another licensee but for that I need the data to clear so I can enter the information again
So I want that command button to clear the form of all previous data and allow me to enter new record. (Kind of like going to a new record in Macro), but I need that for VBA.
This sounds as if this is an Unbound Form and you're using code to insert data into your Table...is that correct?
If so, there is no 'New Record' to go to, because an Unbound Form contains no Records...new or otherwise...it only contains Data in Unbound Controls that can then be written to a Table.
Yes you are right it is an unbound form
so is there no way to clear the data to enter a record?
I'll have to close the form and come back every time to enter new information?
As I said before, in an Unbound Form there are no Records, new or otherwise. As for clearing your Controls, that's simple enough, you just loop through them and set them to empty:
Code:
Private Sub Cmd_AddAnother_Click()
[COLOR="Red"]Dim ctl As Control[/COLOR]
Dim strMsg As String
strMsg = "Do you want to add another License?"
If MsgBox(strMsg, vbYesNo Or vbQuestion) = vbYes Then
[COLOR="Red"]For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox Then
ctrl.Value = ""
End If
Next[/COLOR]
End If
End Sub
Having said that, the question many of us here would ask is...why are you using Unbound Forms in Access? Using Unbound Forms really does away with the basic function of Access, which is to facilitate RAD (Rapid Application Development) and should only be attempted by very experienced Access developers, and then only when/if a legitimate purpose requires it, and most situations don’t! You don't need Unbound Forms to
Do Data Validation
Prevent Duplicate Records
Do Formatting of Data before it's Saved
Decide whether or not to actually Save a New or Edited Record
which are the most common reasons given. Nor are they needed for another dozen reasons I've seen people give!
Several developers I know, experienced in Visual Basic database development and Access development, estimate that development, using Unbound Forms, by highlyexperienced developers, takes two to three times as long, using Unbound Forms, as it does when using Access and Bound Forms. That’s because with Bound Forms the Access Gnomes do the vast majority of the heavy lifting; with Unbound Forms the developer has to write code for everything...even the most mundane tasks!
Your problem, here, is a perfect example of that! Rather than you having to code the above, with a Bound Form, all the user has to do is click on the 'New Record' button, and Access takes you to a new, blank Record.
Bottom line is…with Bound Forms you end up writing code for a few specialized situations, such as #1-#4, as listed above…and with Unbound Forms you have to write code for virtually everything that needs to be done!
If you insist on using Unbound Forms, you'd be far better off using a straight VB or C++ front end with a SQL Server or Oracle back end.
You can create an EXE file which gives total protection to your code/design
You can distribute the db to PCs without a copy of Access being on board
Your data security is far, far better than anything you can do in Access
Don't misunderstand me...there are a few, specialized situations, where an Unbound Form is preferable...but anyone who routinely uses them for everything, has simply made a bad choice in deciding to work in Access.
Thank you very much. I just studies what you just wrote and yes that was a mistake and I'm contemplating rather I should make a new form from a query?
My professor told me laziness is not acceptable in Access and I'm seeing the result now.