Convert Access database to VB project
Hi :WAVE:
I am a new bee here and i am in a great problem. Well I am doin a project in which i need to search the co-ordinate of Y-axis for given X- axis from many tables.
I have the data for x and y values for each table. Now I want to create a database in Microsoft access and upload it in my project so that when i convert my project to exe it can work in any computer.
If any one can give me a detailed procedure I will be very thankful to him.
Tava
# 1 Re: Convert Access database to VB project
There are lots of methods for doing this. Your question is not very clear. If all you have are x and y values in each table then you could load the values in by importing data files, or keying them in manually. If they are already in text files you could use ADO with the text provider and not even use Access at all. Just keep the data in the text files. Once you decide where the data is to be stored then you can open a recordset object using SQL statements to locate the records that you want. Example SQL: Select Y From mytable Where X = 10;
This example would give you a recordset with the Y field of every record from the table called mytable where the X field is equal to 10.
# 2 Re: Convert Access database to VB project
First u must provide near your exe file the database file which containes your tables data ..
Uploading all the tabels data into your exe [like puting it as resource] will not be effective if you want to edit them after that , or it will keep a very large amount of memory every time you want to make any thing on them [not at all effective] ..
Usually we make a database conection like ADO as Ron mentioned , you can add it from your application refrence ,, and as I told u , you will have an exe file and a database file that can runs fine together in any computer .
Amahdy at 2007-11-11 17:24:21 >

# 3 Re: Convert Access database to VB project
thanx for your reply.
well I think i need to explain my work properly.
i have variables Gh, Cp, Fn,Cr
there are nine sheets for different gh values.
Gh: 4 4.5 5 5.5 6 6.5 7 7.5 8
for each Gh value there are 20 Cp curves with X axis for Fn values and Y axis for Cr values.
Now I need to find out Cr value for a given Gh value at a specific Cp curve in a Gh sheet.
This may be very confusing but i have tried my best to explain the problem statement. (I have 9 sheets of paper. in each paper 20 curves(one each for Cp) of Cr(Y axis) vs Fn(X axis).
Now if you can please tell me how to proceed I can start working on that. :(
Please explain how to import or every thing because i am new in VB as well as never used access or SQL. I just need this thing done.please help.
thanx
tava
# 4 Re: Convert Access database to VB project
Where u save them ? in access database ? in exel sheets ? how is your tabels then ?
Amahdy at 2007-11-11 17:26:24 >

# 5 Re: Convert Access database to VB project
Can you tell me which one will be best option for me. if i do it in excell there will be lots of files. so i think acces will be better( as said by access tutorials). where should i keep the access file? and what to do with it?
waiting for reply. :)
# 6 Re: Convert Access database to VB project
you can mail me the procedure( it must be big) in my email id: amitava_iitm@yahoo.com
thanx for help
# 7 Re: Convert Access database to VB project
Can you tell me which one will be best option for me. if i do it in excell there will be lots of files. so i think acces will be better( as said by access tutorials). where should i keep the access file? and what to do with it?
waiting for reply. :)
u can make it in access ?
if so send us a simple table to understand it better .
only the rest is a proper database connection and the SQL string that we will form it for u after seeing the tabel .
Amahdy at 2007-11-11 17:29:28 >

# 8 Re: Convert Access database to VB project
you can mail me the procedure( it must be big) in my email id: amitava_iitm@yahoo.com
thanx for help
it's better to share answers for everybody here right ?
I don't mind to contact u but only to have the benefit for everybody .
moreover if u send us the tabel as I told u we will give u good answers here .
Amahdy at 2007-11-11 17:30:20 >

# 9 Re: Convert Access database to VB project
hi for the problem i have explained above I got a different method to solve that.
as i said i have different curve for a specific Gh and Cp value. So i have made a notepad file which contains two columns one for Fn and one for Cp. What I need is make this type of multiple text file for each combination of Gh_Cp.
whan I get the value of Gh and Cp from previous calculations I need to make a file name as : Gh_Cp.txt ( for ex. if gh=4 and Cp=0.8 the file name should be 4_0.8.txt
now using open filename for input as #1 i can access the values inside the text file.
this solves my problem.
but now the new problem is to create the file name (Gh_Cp.txt)
i have used this code to make the file name but it inserts a space in between i dont know why.
Dim Fname, Gh, Cp, Fn As String
Dim Gh1, Cp1, Fn1 As Double
Dim i As Integer
i = 0
Gh1 = 4 ' lets say this are the values comes from calculation
Cp1 = 8 ' lets say this are the values comes from calculation
Fn1 = 3 ' lets say this are the values comes from calculation
Gh = Str(Gh1)
Cp = Str(Cp1)
Fn = Str(Fn1)
Fname = App.Path & "\data\" & Gh & "_" & Cp & ".txt"
can any one help me to create a file name from numbers and please comment on the procedure i found.
thanx.
# 10 Re: Convert Access database to VB project
well I have removed the unnecessary space created by str() function using LTrim$(str(Gh)) etc.
now can any on tell me what the exact code i need to use for reading the columns of the text file.
# 11 Re: Convert Access database to VB project
one more doubt please
in nearly every software we see there are previous/next buttons to go to the previous or next page of the software. how to do this.
is it using
form2.show
me.hide
please answer as soon as possible.
# 12 Re: Convert Access database to VB project
For one thing if you don't provide a data type for your variables then VB defaults to type Variant. So Fname, Gh, Cp, Gh1, and Cp1 are all variants not strings or doubles.
If you use the CStr function in stead of the Str function you won't get the leading space. Here is the revised code:
Dim Fname As String, Gh As String, Cp As String, Fn As String
Dim Gh1 As Double, Cp1 As Double, Fn1 As Double
Dim i As Integer
i = 0
Gh1 = 4 ' lets say this are the values comes from calculation
Cp1 = 8 ' lets say this are the values comes from calculation
Fn1 = 3 ' lets say this are the values comes from calculation
Gh = CStr(Gh1)
Cp = CStr(Cp1)
Fn = CStr(Fn1)
Fname = App.Path & "\data\" & Gh & "_" & Cp & ".txt"
Also as far a reading two columns it depends on how you seperated your coulumns. Are they serprated by a comma, or a tab character, or a space? Whatever you used you need to find the location of the seperator character and then split the string apart from there. For example if you used a comma then this should work:
Dim Buf As String
Dim Col1 As Double
Dim Col2 As Double
Dim p As Long
Open Fname For Input As #1
Do While Not EOF(1)
Line Input #1, Buf
p=InStr(Buf, ",")
Col1 = CDbl(Left(Buf, p-1))
Col2 = CDbl(Right(Buf, Len(Buf)-p)
Debug.Print Col1, Col2
Loop
Close #1
# 13 Re: Convert Access database to VB project
Yea as Ron told u in vb not like c++ and any other langs ..
dim a,b as byte '>>> b only is byte
'to check that :
b = 300 'error
a = 300 'OK
about the sequential shows like in wizards forms , u may put many "frame" control and in the same form make :
frame1.hide
frame2.show
and will be better if u use array of frames :
frame(i-1).hide
frame(i).show
Amahdy at 2007-11-11 17:35:28 >

# 14 Re: Convert Access database to VB project
can u explain what is the use of p-1 and Len(Buf)-p.
By the way thank you very much for the code. That works fine and I have done the coding for my application using your code.
One problem i am facing now is i am digitizing a curve from a scanned page and the software i am using exports the x axis and y axis values as two columns in .csv file.
I am coping the values of two columns and pasted them in a text file. Can you tell me what is the separator used in csv files. becoz otherwise i have to delete all the gaps between the two values in a row and type a space between them. I think they are separated by a Tab but what should I type instead of "," in
p=InStr(Buf,",")
and can you tell me how to clear debug window?
thanx a lot
# 15 Re: Convert Access database to VB project
Another question
While defining the data type if we use varient don't they use more space than if we define exclusively what is going to be the data type.
# 16 Re: Convert Access database to VB project
About that Wizard type form ( with Next/Back buttons) How can I design multiple frames in one form. while drawing 2nd frame 1st frame cant be seen and if i need to change any thing on first frame i need to replace the 2nd frame to some where and then do the modification in 1st frame which is very difficult in case of big frame. can you tell me the exact procedure how to do this and if i am doing some silly mistake.
# 17 Re: Convert Access database to VB project
csv stands for comma seperated values, so the comma is the seperator.
p is the variable that I used to save the location of the comma. p=InStr(Buf,",") so Left(Buf,p-1) would be all the characters from the beginning of buff to p minus 1. Example: buf ="100,2000" and p=InStr(Buf,",") sets p to 4, so p-1=3 and left(buf,3)="100"; Right works like left but from the right side of the string so Len(buf)=8 and 8-p=4 so Right(buf,4)="2000". You could also use the Mid() function instead of right so p+1 is just past the comma therefore Mid(buf,p+1)="2000" also.
# 18 Re: Convert Access database to VB project
Can you tell me about frame handling if there are any proper method. I can change the left value of the 2nd frame which one i am not editing at this time to -1000 to hide it and edit the 1st frame and vice versa. but if there are any other method please tell me.
# 19 Re: Convert Access database to VB project
thanx Mr.Ron for your help. Now I think I can complete my project. :)
I am really grateful to you.
# 20 Re: Convert Access database to VB project
Is that frame method is good enough if I have a long process tree i.e I may need 20 such frames in one form.
# 21 Re: Convert Access database to VB project
There is a member called (hide) that could help u better :
creat an array of frames [20 frames say]
hide them all from the proprieties window exept the first one only
u can make in the next button :
frame(i).hide
frame(i+1).show
and the inverse for back button ;
that's all, in each frame put what u want separetly and only one next/back button will navigate between them all but care to make the index "i" a static and increase every nex and decrease every back, also u can make the next button.disabled if i = 0 , same for next if i=20 .
Amahdy at 2007-11-11 17:43:38 >

# 22 Re: Convert Access database to VB project
Sorry, but there is no Hide property for frames in visual studio 6 (what i am using).
only visible property is there but it doesn't hide the frame at design stage, it hides the frame while the application is running. Your code is fine and the application will run properly but the problem is during design stage.
:(
# 23 Re: Convert Access database to VB project
Ah I'm sorry I mean all time the (.visible) , it must work well now okey ?
Amahdy at 2007-11-11 17:45:36 >

# 24 Re: Convert Access database to VB project
To make the Frames all same in size and position i think the best option is making a function to set all the values for the frames. But the problem is what should i set the data type of that function. I have made the code as:
Public Function ShowFrame(ByVal i As Integer) as ??
Frame(i).Show
Frame(i - 1).Hide
End Function
and in the next button i have written
Private Sub cmdNext_Click()
Dim i As Integer
If Frame(0).Visible = True Then
i = 1
ElseIf Frame(1).Visible = True Then
i = 2
End If
ShowFrame (i)
End Sub
Can you tell me which data type should i give to the ShowFrame function.
# 25 Re: Convert Access database to VB project
Well the .visible is okey when the program is running but while designing the frame its a mess when all 20 frames are in one form each having same size and position.handling them is troublesome.
# 26 Re: Convert Access database to VB project
To make the Frames all same in size and position i think the best option is making a function to set all the values for the frames. But the problem is what should i set the data type of that function. I have made the code as:
Public Function ShowFrame(ByVal i As Integer) as ??
Frame(i).Show
Frame(i - 1).Hide
End Function
and in the next button i have written
Private Sub cmdNext_Click()
Dim i As Integer
If Frame(0).Visible = True Then
i = 1
ElseIf Frame(1).Visible = True Then
i = 2
End If
ShowFrame (i)
End Sub
Can you tell me which data type should i give to the ShowFrame function.
use public sub and don't put any return type , [u can do the same for functions i.e. public function myfunc() 'only]
and call it like that in the two cases :
showframe i 'without brackets
Amahdy at 2007-11-11 17:48:38 >

# 27 Re: Convert Access database to VB project
Well the .visible is okey when the program is running but while designing the frame its a mess when all 20 frames are in one form each having same size and position.handling them is troublesome.
u have two solutions the first one is to move between frames using the "send to back" method when u right click on it , or the second and this if u r creating a real wizard : use the sample vb wizard manger , using the add-on wizard manger .
Amahdy at 2007-11-11 17:49:43 >

# 28 Re: Convert Access database to VB project
This send to back method is fine and i am going for that. thanks :)
# 29 Re: Convert Access database to VB project
How to write multiline text in labels? I want to give some information of my software at the beginning , how to that?
# 30 Re: Convert Access database to VB project
label1.caption = "line1" & vbcrlf & "line2" & vbcrlf & ...
vbcrlf = vbcr + vblf [line feed]
Amahdy at 2007-11-11 17:52:48 >

# 31 Re: Convert Access database to VB project
Is there any way i can find out which frame is currently visible in the application. i need the array number of the frame to optimize the program for back and next button.
I have written this code for next and back button:
Private Sub cmdNext_Click()
Dim i As Integer
i = frame.???????????????
If frame(i).Visible = True Then
i = i + 1
End If
ShowFrame i
If i >= 0 Then
cmdBack.Visible = True
End If
End Sub
Public Function ShowFrame(ByVal i As Integer)
frame(i).Visible = True
If i > 0 Then
frame(i - 1).Visible = False
End If
End Function
please help.
# 32 Re: Convert Access database to VB project
more precisely can i find what is the index of the currently visible frame and in which data type i can store that
'some code to find out the currently visible frame ???
'dim i as data type? ?????
i=frame(index)
' code for the next button
# 33 Re: Convert Access database to VB project
let me give u a small update in your code may it help u :
'declarations:
Dim i as integer
'-----
Private Sub cmdNext_Click()
frame(i).Visible = True
frame(i - 1).Visible = False 'i +1 for back
i = i + 1 ' i = i - 1 for back
if i = 20 then 'if i = 0 for back
cmdNext.enabled = false 'cmdback
else
cmdNext.enabled = true 'cmdback
end if
end sub
Amahdy at 2007-11-11 17:55:49 >

# 34 Re: Convert Access database to VB project
My question is how to find out i ?
that is the index of currently visible frame.
# 35 Re: Convert Access database to VB project
okey man I have told u how to find it by coding method :)
the solution is to put i as public variable and it will contains the visible frame all time , otherwise u can make i static variable in any of your functions .
Amahdy at 2007-11-11 17:57:48 >

# 36 Re: Convert Access database to VB project
Can you explain what value of I will be saved when I write
Dim i as Integer
Frame(i).Visible = True
# 37 Re: Convert Access database to VB project
I need the value of i for other functions, such as changing the caption of the labels in different forms. what i have to wright to get the value of i
# 38 Re: Convert Access database to VB project
Well i have solved that problem!
Now can any one tell me how to handle this error.
i have a number of text files which contain data for specific values.
i have given every constrains possible so that no user can enter alphabet or leave a textbox empty. but if the user enters arbit values then my program will generate a file name and it tries to open the file from the concerned folder.
I have the file name . Now how can i check if any file with that file name existas or not. if they don't exist i want to give a msg that "file doesn'ty exists in database"
+ "try again!!".
how can i do this?
# 39 Re: Convert Access database to VB project
I wrote this program :
On Error Resume Next
Cr = FindCr(Gh, Cp, Fn) ' this is the function which opens text file from for input.
If Error <> 0 Then
MsgBox "error"
Exit Sub
End If
but it's giving error every time dont know why?
can you help?
:(
# 40 Re: Convert Access database to VB project
first of all check if your function haven't errors ..
if err <> 0 then .. or if err.number <> 0 then ...
about i I told u to make it public , and if u wish u can make a string of restricted charcters and check over them to solve your error problem .
Amahdy at 2007-11-11 18:02:52 >

# 41 Re: Convert Access database to VB project
thanks Mr.Amahdy
That err.number<>0 works fine. :)
# 42 Re: Convert Access database to VB project
First of all I want to wish you all a very happy new year.
Now my question is "is there any way to clear the debug window each time i run the application ?"
# 43 Re: Convert Access database to VB project
I don't think so , but sometimes you can make something like that on the load of project :
debug.print vbcrlf & vbcrlf & vbcrlf
Amahdy at 2007-11-11 18:06:03 >

# 44 Re: Convert Access database to VB project
I am having a problem which i don't understand why is it happening?
As I said before that I need to open a file to read data from that and the file name is created by the program. i.e if
Gh=4
Cp=0.75
Then the file name will be
Fname=App.Path & "\Data\Gh" & Cstr(Gh) & "_" & "Cp" & Cstr(Cp)
So Fname becomes ...\Data\Gh4_Cp0.75
Now the problem is if that file is not exists in the Data folder then the program will generate an error.
To overcome this problem I have written this:
'==============================================================
On Error Resume Next
Cr = FindCr(Gh, Cp, Fn)
If Err.Number <> 0 Then
MsgBox "Sorry ! There is some error. The reason can be either" & _
vbCrLf & "1. Data for this ship is note yet updated." & _
vbCrLf & "2. The type of ship is out of range for this method" & _
vbCrLf & "3. There must be some mistake in input" & _
vbCrLf & "Check your data properly and enter the data cautiously.", vbExclamation, "Error"
Exit Sub
End If
'===============================================================
Here FindCr(Gh,Cp,Fn) is a function which opens a file of name(Gh.._Cp..) as explained before.
The problem is when i click the calculate button of my application with a data for which the file is not exists it shows an error. Then when I give input for which the file exist then also it gives some error msg.
Then I have to close the program and then when i reopen it and give the correct inputs( i.e file exists) then it gives me result.
So how to improve this? I want to give various inputs and check whether the file exists or not without closing the application.
i am sure you will help.
thanx
# 45 Re: Convert Access database to VB project
I'm sorry but I can't understand your structure sequence ...
when findcr() return an error the msgbox() popup then what ? what u do ? and what make errors ? r they run-time errors ? where exactly ? u may make "on error resume next" or "on error resume goto err_handler" for example to catch the error at it's location ... or try debug mode to know where the error occure exactly .
it's better to post the location that contains error exactly and the error msg .
Amahdy at 2007-11-11 18:07:56 >

# 46 Re: Convert Access database to VB project
I don't need to handle error. if its giving an error that mean there is no file named the program returns and its actually not an error of the program, it can only happen if you give some arbit inputs for which there will be no such file present in the data folder.
In that case i just want to display a msg to the use that "hallo, why are you tryin arbit numbers? " :P and then again let them input proper numbers.
Can you tell me how to handle this situation.
# 47 Re: Convert Access database to VB project
Well i forgot to mention the location of error:
Error occurs when i try to open the file
open Fname for input as #1
becoz no such file is present in the location.
# 48 Re: Convert Access database to VB project
Use the Dir() function to see if the file exists. Like so:
Fname=App.Path & "\Data\Gh" & Cstr(Gh) & "_" & "Cp" & Cstr(Cp)
If Dir(FName)="" Then
MsgBox ....
End If
# 49 Re: Convert Access database to VB project
It's a runtime error right ?
u can for example put this statment on the top of your procedure :
On Error Resume Next
this method will work but it's not the better method to catch such an error ..
generally there r better methods to check for the existance of the file like dir() function .
Amahdy at 2007-11-11 18:12:08 >

# 50 Re: Convert Access database to VB project
Hello
Thank you all for your support and help on my project. I have finished my project (described on the thread "getting data from excel sheet" ).
Now a problem i am facing is when i converted the project to .EXE is perfectly runs in my computer but it says some thing like:
"One component is missing, MSMASK32.OCX is required to run the program"
Please tell me what extra files I should attach with my program and how to attach it so that it works on every computer.
Sorry if this is not a related thread but i could not find one so i am trying this on. please help me. I have made all the coding etc and now if it doesn't run in the peoples computer then my all effort is use less.
Thanks
bye
TAVA
# 51 Re: Convert Access database to VB project
Hello
Thank you all for your support and help on my project. I have finished my project (described on the thread "getting data from excel sheet" ).
Now a problem i am facing is when i converted the project to .EXE is perfectly runs in my computer but it says some thing like:
"One component is missing, MSMASK32.OCX is required to run the program"
Please tell me what extra files I should attach with my program and how to attach it so that it works on every computer.
Sorry if this is not a related thread but i could not find one so i am trying this on. please help me. I have made all the coding etc and now if it doesn't run in the peoples computer then my all effort is use less.
Thanks
bye
TAVA
a bit off topic...
but, to make the application work you have to copy the file 'MSMASK32.OCX' which is probably on your development workstation to the computer you are trying to run the application on and register it.
To register the DLL/OCX you need to double click on it, and when windows asks you how to open the file, browse to c:\windows\system32\regsvr32.exe and make this the handler for OCX files (select to open the OCX with this program) which will then register the file for you and allow the program to work.
A better solution would be to package and register the file automatically in the installer, I think the package and deployment wizard will do this for you aswell as clickonce, or get a third party deployment utility, i used createinstall free when I was developing in VB6.
Hope this helps
-Dan
