& thanks for all the tips i've had here... this site is ace!
My question is, basically, how to correctly write my script. I've written an applescript, that works great for 1 variable, but i'll need to add hundreds of variables, and that'll currently mean adding hundreds of "if" statements.
So my script queries a FileMaker database & receives an input field (which is variable), i then want to open a the related textEdit file & read the text.
ie... FileMaker Pro returns "123", so i want to open textEdit file "123".
However, my script currently says If text returned is "123" then do this, else if text returned is "234" do this, else if text returned is "345" do this. To write this script with hundreds of "Ifs" doesn't make sense, but i can't get my head around swapping my script to say - returned value is "123" so use file 123.
Does anyone have a suggestion?
Thanks
Related
I have a query that pulls information I need to use in a mail merge document to email to people for verification of information. There are 8 fields they need to verify, preferably with a check box control, but some of the fields contain no information. I would like to make the check box next to merge fields that contain no data (or whatever I may need to write into the query to make this work) invisible. If this could be accomplished easier in a completely different way, that would be fine too. Thank you.
As Cindy said, this kind of thing is handled via field coding in the mailmerge main document, not via VB code. Such a field might be coded as:
{IF{MERGEFIELD myCheck}<> "" "[ ]"}
or:
{IF«myCheck»<> "" "[ ]"}
where 'myCheck' is the field name and '[ ]' is the checkbox content control.
Note: The field brace pairs (i.e. '{ }') for the above examples are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac or, if you’re using a laptop, you might need to use Ctrl-Fn-F9); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. Likewise, the chevrons (i.e. '« »') are part of the actual mergefields - which you can insert from the 'Insert Merge Field' dropdown (i.e. you can't type or copy & paste them from this message, either). The spaces represented in the field constructions are all required.
I have folders labeled by their keyfield, so 1, 2, ... 999, 1000. located in currentproject.path\RecordFiles\KeyFieldHere so like currentproject.path\RecordFiles\917.
I want to run a query that will count how many files are in each folder. I know this can be done with the DIR function through visual basic, but I can't seem to run it through a SQL query.
I've tried using this function in a SQL equation, so Expr1: [FlrFileCount("Y:\Education\Databases\RecordFiles\")] as one of the fields just to see if it can work, but it prompts me for a value and then returns nothing.
EDIT: I tried an approach using the FlrFileCount function in a continuous form, and it does work, BUT... I get an error after every single line. I have a field in a continuous form of =FlrFileCount([currentproject].[path] & "\recordfiles\" & [ID]), but when I run the form I get an error "Error 76, Error source: FlrFileCount, Error description: Path not found." Which is crazy because IT WORKS, it properly lists the number of files in the folder for each record.
I just need to get this functionality over into a SQL query so I can pull that data for mail merges.
I currently have something similar in a form. The form has an onload property to run a module (Link here) to create a list of all the files in the relevant folder to that record, and then I have another field that just counts the number of entries in the list. However a list can't be a value in a SQL query, so I don't think that code will help.
Thanks to Tim Williams, the answer was to put
=FlrFileCount(Currentproject.Path & "\recordfiles\" & [ID])
It seems the [currentproject].[path] part was where the error was. What's confusing is that in other places, MS Access adds the extra [] around currentproject and path, and I don't know why.
Thank you so much for your help! Now to the tricky part: Implementing a proper naming scheme by program ID across a sharepoint so that the relevant folder can be opened consistently even when program names change.
TL;DR:
Is there a way to embed a console inside a form, so it becomes a part of it?
Scenario:
I am writing a chat-application with client, server and database using Windows Forms in VB.NET. The server should log all communication it has with clients in a textbox.
The Problem:
So far that would not be a problem - If there wasn't a maxlength for strings! I expect this server to almost never stop (Okay, there is always some point where it does.. but lets ignore that). So if i go for Textbox1.Text &= vbnewline & "Something" it will some day reach this length and run into an exception each time something is about to be logged. I also don't want to just remove the first characters of the string.
My Idea for a solution:
My idea for a work around: Use a console instead of a simple textbox and embed it into the form, so it becomes a part of it. Is there a simple way to do that? By simple I mean that I should have to write thousands of lines of code to achieve that goal.
I am open minded for different ideas and ways to do so as well.
Why not just log your chat to file (you could create a file per day)?
Dim filename = String.Format("C:\Temp\{0:yyyy-MM-dd}-log.txt", DateTime.Now)
My.Computer.FileSystem.WriteAllText(filename, "line of text", True)
Then to display it - use a ListBox and append each new line to the end of the listbox? Each time you append, you could check how many items are in the listbox and remove the first 100 if you are over 1000 as an example.
I'm trying to export a crosstab query from Access 2010 to a csv without a text qualifier. I'm able to use the Transfer Text method with my other exports; the trick with this one is that the number of fields (and their names) change depending on what the user selects on the form, but the setup in the SpecificationName is static. If I don't indicate a SpecificationName, I can get whatever fields are run in the query as appropriate, but I get quotes around my text fields, which I don't want. If I set up a specification to set the text qualifier as None, I'm stuck with a set list of fields. I tried sticking an asterisk in the FieldName area when setting up the specification, but got
The number of fields in your export specification does not match the number in the table you have chosen to export.
I'd really like some kind of "SELECT *" in there, but it doesn't look like it's possible?
Poking around, it looks like I might need to set up a schema.ini? Of course, this would need to be dynamic as well. I found a resource that was written for Access 97: https://support2.microsoft.com/default.aspx?scid=kb;en-us;155512, but it doesn't seem to work in Access 2010. Even after updating db As Database to db As DAO.Database, I get
Expected variable or procedure, not module
When running the following in the Immediate window (with appropriate text subbed in):
?CreateSchemaFile(True,"C:\MyFilepath","ExportFileName.txt","qryCrosstabs")
I've reached the limits of my (limited) VBA chops to figure this out. Writing a script for a dynamic schema.ini seems like overkill for just wanting to get rid of quotes, but if that's what has to happen, any pointers in the right direction would be excellent.
Thanks!
Ah, ok, I figured it out. I thought I had to specify the columns in Schema.ini, but I was mistaken. I just needed to set the header to true; that way it'll read whatever happens to end up in the query. Setting the text delimiter to none was also a key piece.
Here's all I needed in Schema.ini (just needs to be in the same directory as the exported file):
[ExportFileName.txt]
Format=CSVDelimited
ColNameHeader=True
TextDelimiter="none"
And the code:
Private Sub cmdExport_Click()
Dim dbs As DAO.Database
Set dbs = CurrentDb
dbs.Execute "SELECT * INTO [text;database=C:\filepath].[ExportFileName.txt] FROM qryCrosstabs"
While this ultimately works, having an external Schema.ini file is clunkier than I'd like. I've seen a few places where adding extended properties to the dbs.Execute line will indicate csv (FMT=Delimited) and column headers (HDR=Yes). Having one for text delimiters would be the most parsimonious solution, but from what I can tell, that doesn't exist. I'm happy to be corrected on that if it does, though!
I'm basically trying to create a program that will allow me to use textboxes to input questions and associated answers to test myself. Mostly, I just want to practice some things I've been learning for vb.net while taking an extra step forward.
Here's a mockup:
Any tips on how to do this? What I'm especially not sure about is how to have the textfile save/import work with adding back into comboboxes and making sure the correct questions and answers are associated with one another. I was thinking also that I could have some sort of check when I import a save file that shows me which questions and answers refer to one another
Update on form design:
Some things I'm trying to practice:
Using arrays
Saving/Opening files (text files in this)- in order to import into program
importing into program
Using the progress bar
Having a way to undo entries
Randomizing sort order in the combo box
Maintaining references between variables (like which answer
corresponds with which question) regardless of sort order or using
the undo function
Some posts in stackoverflow I'm thinking of using as reference:
Compare String with Strings in array
Best way to associate two strings of text in VB.NET
Array to combo box?
Update: Trying to be more specific on my question. Basically, I'm trying to use a list to account for all the inputted questions and answers, however I've only used really basic arrays before, like:
val(1) = "test"
val(2) = "this"
val(3) = "string"
Or the kind where you use a For x to z loop. Based on some stackoverflow posts I've gotten to the point where the code works in that (I think?) the list is updated and the combobox for questions and answers reflect what is on the list. However, I can't connect the two so that I can select things in the comboboxes and check if they are correct.
In terms of saving as a text file. I figured it would be simpler. Basically, have it output sort of like
"question goes here" ; "answer goes here"
"next question goes here" ; "answer goes here"
and so on. Then I can use the semicolon as reference in the code when importing. I've never done it before, but it's generally what I do for Microsoft Access or Excel text imports so I figured it was possible.
Code that I have so far (reddit post link): http://redd.it/2716tw