VBA not working (1 Viewer)

longbreak

Registered User.
Local time
Today, 03:03
Joined
Oct 29, 2012
Messages
10
Hello, I have been using access 2010 for a few weeks now and thought I was ready to try first project which was to be a db for servicing a vehicle with service details, mileage, due dates etc. However I ran into my first problem from scratch. I put a textbox in the header of a form and was hoping to use vba to insert string from a table field such as vehicle model. I found I couldn't even just insert a string into the textbox. It just does'nt show when the form opens. So I made a very tiny db to begin for the express purpose of making this happen but the string doesn't get to the textbox for some reason. If I cannot do that then there is no way of going forward.
My
vba script is pretty simple and I have included a msgbox which doesn't come up so that confirms there is null entry in the textbox. Very grateful if someone could help.
Option Compare Database
Option Explicit
Dim carton As String

Private Sub Text5_
AfterUpdate()
carton = "Bugger"
MsgBox "The value is" & " " & carton
Text5 = carton
If
IsNull(Me.Text5.Value) Or (Me.Text5.Value = "") Then
Exit Sub
Else:
MsgBox "The value is" & " " & carton
End If
End Sub
I then tried adding the following to form properties in
vba:
Private Sub Form_
AfterUpdate()
carton = "Bugger"
MsgBox "The value is" & " " & carton
End Sub
That also is not working so it looks like the
vba just does nothing or is not even linked to the db even though I explicitly added the code to vba from the form properties. I think this is the real reason why I am missing something I don't understand how to force vba to do it's work on the form. Such a trivial but frustrating error.
 
Last edited:

John Big Booty

AWF VIP
Local time
Today, 20:03
Joined
Aug 29, 2005
Messages
8,262
The Code works fine. You do realise that you have it in the Form's After Update event? Which will not fire until after the form is updated. Which doesn't happen until you move to a new record.
 

longbreak

Registered User.
Local time
Today, 03:03
Joined
Oct 29, 2012
Messages
10
Thanks for the confirmtion. So there must be something else causing vba not to talk to the form. I should look at some mystery settings in access which are causing this. In the meantime I found a sample mdb which might have similar actions which I can check. It is dbSearchExample which I found on this forum. Failing that I might ask if someone could upload a working example of my little db.
 

longbreak

Registered User.
Local time
Today, 03:03
Joined
Oct 29, 2012
Messages
10
I think I misunderstood you before John. When you said the code works fine I thought you ran it on a separate test db. After I uploaded the TextBoxTest.accb I thought the upload didn't work as it should have been zipped but now I see it did.
Can you confirm you ran that file and it worked? Plenty of msgbox should pop up which is what I am not getting.
 

John Big Booty

AWF VIP
Local time
Today, 20:03
Joined
Aug 29, 2005
Messages
8,262
Yes I ran the file you uploaded and the code ran just fine, But I suspect you want it in the Field's After Update rather than the Form's After Update.
 

longbreak

Registered User.
Local time
Today, 03:03
Joined
Oct 29, 2012
Messages
10
OK many thanks for that. The only reason I also included it in the Form update was in frustation to see if I could get it to work anywhere. I only put a declaration and a msgbox in there to see if a msgbox would work, so whether it worked or not there should be two msgbox events. This tells me that the vba code is doing absolutely nothing on my program......what a mystery. Thanks for your help anyway. I will be away for a couple of days now and when I return I will do something crazy like getting MS Access to repair the installation.
 

longbreak

Registered User.
Local time
Today, 03:03
Joined
Oct 29, 2012
Messages
10
Just made it back and had another look at this. First I had Access 2010 do a repair job but that did no good. I see that there are some problems experienced by some users where VBA does not link with access either on security issues or old versions of access conflicting but these were not helpful. Then I looked at an old file that I have that is working but via a command button so I had a bit of fun putting a button into this file and it works, a message box pops up and the field gets filled and appears but the rest of the code is just dead. Yet John you claim that it all works so I am definitely missing something. Disabled antivirus as well with no result. I will proceed by using a button for now but will also keep trying to find a way to dispense with the button if possible.
 

longbreak

Registered User.
Local time
Today, 03:03
Joined
Oct 29, 2012
Messages
10
Just to set the record straight the problem was myself. The only way to code this process is by using Form On Load and it works.
So can I delete this conversation to hide my embarassment?
 

John Big Booty

AWF VIP
Local time
Today, 20:03
Joined
Aug 29, 2005
Messages
8,262
Perhaps someone else will be lucky to learn from your mistake. Simply chalk it down as a learning experience ;)
 

Users who are viewing this thread

Top Bottom