First, I am not sure what Cancel As Integer means, it was in their by default when I created the script and the script doesn't seem to run without it.
This means that you can Cancel exiting the control in question, the textbox BarCode, in this case. If you had the need to do that you would use
Cancel = True
And yes, the Exit event it will not run without
Cancel As Integer in the sub header. Never change the sub headers that Access generates, and never try to add things like
Cancel As Integer to sub headers that Access generates that lack it; it also won't work.
Second, even though the script runs, it does not appear to do anything. I believe it is because I haven't saved the record in Table1, but I can't locate a command to do that.
You have to actually Exit the BarCode textbox before the code will execute.
In Access, you don't normally need a "save" button, as Access is designed to save a record when you either move to another record or close the form. If there is a reason to force an explicit save, you can use
If Me.Dirty Then Me.Dirty = False
Since you only have one other control on your form, and you're filling that thru code, I'm guessing that you haven't exited the BarCode textbox. If you move to another record or close the form while the cursor is still in it, its Exit event will fire.
In Access, when referring to a control such as a textbox, from within its own code module we use the preface
Me. So your code would read
- Private Sub BarCode_Exit(Cancel As Integer)
-
-
If Me.InOutFlag = True Then
-
Me.LastOut = Date
-
Me.InOutFlag = False
-
Else
-
Me.LastIn = Date
-
Me.InOutFlag = True
-
End If
-
-
End Sub
If I knew what I was doing, this would be simple. I have already spent too much time looking around for help on this, so I hope someone here can make me not so clueless.
I have to say that you really, really need to get a book or two and do some reading to get a basic idea of how things work before attempting to develop your database! While Access allows for the rapid development of databases, it is very complex program and not something you can "jump into and figure out" in the same way that you would, say, a word processing program or even a graphics program.
The mission of this forum is to answer specific questions about specific technical problems, and the people responding here are always happy to do so, but we expect the posters to have put out a certain amount of effort to both learn Access and to solve their problems before coming here.
So using the info above, give this a try and see what happens. If you have problems, come back here with the details and we'll see what we can do.
And read a book or two!
Welcome to
Bytes!
Linq
;0)>
Moderator