VBA Command Buttons not working (1 Viewer)

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:09
Joined
May 21, 2018
Messages
8,463
Any chance you can post a very stripped down version? One form and enough other things that would demo this behavior. The table could have some fake data if needed.
You may be able to post it with the tables, but no data in the tables.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 11:09
Joined
Sep 12, 2006
Messages
15,614
You don't HAVE to move from an mdb.. Access will run mdb's

Maybe it's a bitness issue or a references issue.
If you use tools written for 32bit Access, and your new Access is 64bit, you may well get issues.

If you just open the mdb in A365, and save as an accdb, A365 will chack all the conversions. I think that's what @Pat Hartman and others were getting at.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:09
Joined
Feb 19, 2002
Messages
42,981
What is the code in the command buttons?
 

kevnaff

Member
Local time
Today, 11:09
Joined
Mar 25, 2021
Messages
141
Any chance you can post a very stripped down version? One form and enough other things that would demo this behavior. The table could have some fake data if needed.
You may be able to post it with the tables, but no data in the tables.

Hi MajP

I can certainly do this, but before I do; I have created a new blank database. I have tblNames containing 3 records. I have frmMainMenu with 2 command buttons. The first uses a macro to open frmNames, this works OK. The second uses VBA to attempt to open frmNames, but doesn't work.

What VBA code can be used to simply open the frmNames?

I am attempting to use DoCmd.OpenForm (frmNames)

Is this the correct way to open a form like this. I am used to copying over existing code and editing it to suit what I need to do.

Please see below a link to this test database that the VBA code is not working in if anyone can help?

 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:09
Joined
May 21, 2018
Messages
8,463
In the VBA editor go to Tools, Options, and check "Require Variable Declaration"
What this will do is on every module at the top you will see the words

Option Compare Database
Option Explicit

Option explicit means you have to declare variables

Dim frmName as string
frmName = "SomeFormName"

If you do not declare the variable with a dim, public, or private VBA will warn you. This would have caught your problem and warned you

DoCmd.OpenForm (frmNames)

It thinks that frmNames is a variable. You want a literal which is

DoCmd.OpenForm "frmNames"

Now for the really weird part. That tiny db was 136 Megs. When I compacted it, it went down to 544k. Something bad is going on with your version of Access that would do that. Did you make that DB in O365 or is that a conversion? Is it really 136 Megs on your machine? Never seen that. So there is possibly either a significant conversion problem or a problem with O365. Are other dbs bloating like that.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:09
Joined
May 21, 2018
Messages
8,463
I am used to copying over existing code and editing it to suit what I need to do.
IMO the Access object model (objects, methods, properties) on line is very good. If you have a question about a method you can type it in. I consider myself a pretty advanced VBA coder and I reference it all the time.

 

LarryE

Active member
Local time
Today, 04:09
Joined
Aug 18, 2021
Messages
562
If you use:

DoCmd.OpenForm "frmNames", acNormal, , , acFormEdit

to open the form it works fine. Your syntax was wrong.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:09
Joined
Feb 19, 2002
Messages
42,981
1, Adding Option Explicit after the fact does NOT change any existing modules. You will need to open every module directly and add the Option Explicit to the top of it and save the module.
2. If your syntax was wrong, I don't know why the data base worked before conversion. It should always have had the same problem
3. I didn't look at your sample. Please use the site features to upload your database if you want anyone to open it.
 

kevnaff

Member
Local time
Today, 11:09
Joined
Mar 25, 2021
Messages
141
Hi All.

So I opened the database that I attached via a link above on my laptop at home, and once I had corrected the code it worked completely fine. I have changed the code on my copy in work, and it does not work. When I opened it on my personal laptop, a yellow message bar appeared for me to click on, I can't remember what it said, but I imagine it allowed my computer to trust the database/to allow edits.

I have since tried to split my test database, and had the following message when trying to use the built in function:

1635857307264.png


When I try to manually do it using the save as to create the front end .accde, I get the following message:

1635857349393.png


Despite the message, no message bar appears to allow me to enable this. I am hoping that once I trust the database, then this may correct the issues I'm having. Either way, I need to trust the source of the database. Is there a way of manually doing so?

My trusted locations options are all greyed out:

1635857431767.png


Thanks all for your advice.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:09
Joined
Feb 19, 2002
Messages
42,981
I have since tried to split my test database, and had the following message when trying to use the built in function:
Splitting the database would not cause this error. Can you open any other databases?

The solution is almost certainly to reinstall Access. If you go through a detail install, you have an option to select this option. If you let the install go without selections, the wizards are installed by default. If your IT department did this Office install, they may have to help you to resolve the problem.
 

kevnaff

Member
Local time
Today, 11:09
Joined
Mar 25, 2021
Messages
141
Splitting the database would not cause this error. Can you open any other databases?

The solution is almost certainly to reinstall Access. If you go through a detail install, you have an option to select this option. If you let the install go without selections, the wizards are installed by default. If your IT department did this Office install, they may have to help you to resolve the problem.

Thanks Pat, I will ask the IT department to perform a reinstall.
 

Users who are viewing this thread

Top Bottom