Referring to a Table in a with statement VBA

dellehurley

Board Regular
Joined
Sep 26, 2009
Messages
171
Office Version
  1. 365
Platform
  1. Windows
I know this is very simple but I cannot find the answer anywhere.
How do I refer to a table when declaring a with statement (eg below)
Form_frmFileName works for a form however neither Table_tblFileName or simply tblFileName work.

VBA Code:
With Table_tblFileName
            .txtFileName.Value = FileName
            .txtFileNo.Value = FileNo
End with

Thanks in advance.
Dannielle
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Sorry I copied this from another piece of code writing to a form, obviously the textbox info is incorrect.
I have just recently moved over from Excel to Access and I'm still using training wheels...
but I would still like to know if it is possible to use the with statement after
DoCmd.OpenTable "tblFileName", acViewNormal, acAdd
or/and how do I refer to the table and field line by line (without the with statement)?

I know this is very simple but I cannot find the answer anywhere.
How do I refer to a table when declaring a with statement (eg below)
Form_frmFileName works for a form however neither Table_tblFileName or simply tblFileName work.

VBA Code:
With Table_tblFileName
            .txtFileName.Value = FileName
            .txtFileNo.Value = FileNo
End with

Thanks in advance.
Dannielle
 
Upvote 0
I have never edited a table directly except via queries or manually?
Normally a form is recommended, with that table as it's source.
 
Upvote 0
Agree. Even if there is an answer to how it is not something you want to be doing. Might be better if you explained what the process or end goal is.
 
Upvote 0
Oh that is interesting :oops:.This is what I am trying to do...
I have a main form which has several joined forms. The first step on the main form is a command button which opens a browser to select a file, the vba checks whether the file is named using the correct protocol and whether it is in the correct file location. As this is a process I started in excel some files are already named correctly. I thought if they were named correctly that I would bypass the form, reverse engineer the file name, add the required info to the table and continue from there. I suppose the reason that I spent all day yesterday not being able to get this to work is because it isn't something that is done!
 
Upvote 0
As this is a process I started in excel
All of the aforementioned objects (table/form/etc.) are in Access? Not sure I understand what comes after that part of your post. Seems like you're using a file dialog (what you call a browser) so why not just append to a table whatever you need from what the dialog returns? If you're using code for this, you could either use Docmd.RunSql or .Execute method of Database.
 
Upvote 0
All of the aforementioned objects (table/form/etc.) are in Access? Not sure I understand what comes after that part of your post. Seems like you're using a file dialog (what you call a browser) so why not just append to a table whatever you need from what the dialog returns? If you're using code for this, you could either use Docmd.RunSql or .Execute method of Database.
The file name is auto generated by the info supplied on the filename form. The file is selected, renamed, moved to the correct location and if the file is an image the exif or metadata is updated too. As for the "either use Docmd.RunSql or .Execute method of" I will take the advice and look into it. I appreciate you taking the time to reply.
Dannielle
 
Upvote 0
Well you could use a recordset to do what you now appear to be attempting.?
That would pretty much emulate what you wish to do in your explanation.
 
Upvote 0

Forum statistics

Threads
1,221,513
Messages
6,160,244
Members
451,632
Latest member
purpleflower26

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top